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
main
Sam Lantinga 2021-12-17 19:04:39 -08:00
parent 71e3998d6c
commit c31a40246d
1 changed files with 2 additions and 2 deletions

View File

@ -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;
}