From c31a40246db952ed3806992b7fbbb6a6383ad26e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 17 Dec 2021 19:04:39 -0800 Subject: [PATCH] Fix audio memory leaks due to invalid init (thanks Janiszewski!) SDL_Init(SDL_INIT_AUDIO) did not take into account that functions like SDL_AddAudioDevice do register events, which will need final cleanup and only gets fired when events were actually initialised. Sample call stack of a malloc missing its free (Linux + PA): SDL_malloc_REAL (SDL_malloc.c:5328) SDL_AddEvent (SDL_events.c:445) SDL_PeepEvents_REAL (SDL_events.c:531) SDL_PushEvent_REAL (SDL_events.c:762) SDL_AddAudioDevice (SDL_audio.c:443) SourceInfoCallback (SDL_pulseaudio.c:681) context_get_source_info_callback (introspect.c:534) run_action (pdispatch.c:288) pa_pdispatch_run (pdispatch.c:341) pstream_packet_callback (context.c:349) do_read (pstream.c:1012) Fixes https://github.com/libsdl-org/SDL/issues/3005 --- src/SDL.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SDL.c b/src/SDL.c index 7456376775..7d4b61180f 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -169,8 +169,8 @@ SDL_InitSubSystem(Uint32 flags) flags |= SDL_INIT_JOYSTICK; } - if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) { - /* video or joystick implies events */ + if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO))) { + /* video or joystick or audio implies events */ flags |= SDL_INIT_EVENTS; }