From f080336fa6feb4995a58ed4937d30cc87874a188 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 27 Jul 2024 16:26:54 -0700 Subject: [PATCH] Fixed memory leak if logging is done after SDL_Quit() If someone calls SDL_Quit(), then runs an SDL function that implicitly initializes TLS or logging, and then calls SDL_Quit() again, we want to make sure we run through the quit process again. Each of the Init/Quit calls are protected against being called multiple times. --- src/SDL.c | 13 ------------- src/SDL_log.c | 1 + 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/SDL.c b/src/SDL.c index 203358bfd1..848f897008 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -113,7 +113,6 @@ static SDL_bool SDL_MainIsReady = SDL_FALSE; #else static SDL_bool SDL_MainIsReady = SDL_TRUE; #endif -static SDL_bool SDL_main_thread_initialized = SDL_FALSE; static SDL_bool SDL_bInMainQuit = SDL_FALSE; static Uint8 SDL_SubsystemRefCount[32]; @@ -186,33 +185,21 @@ void SDL_SetMainReady(void) /* Initialize all the subsystems that require initialization before threads start */ void SDL_InitMainThread(void) { - if (SDL_main_thread_initialized) { - return; - } - SDL_InitTLSData(); SDL_InitTicks(); SDL_InitFilesystem(); SDL_InitLog(); SDL_InitProperties(); SDL_GetGlobalProperties(); - - SDL_main_thread_initialized = SDL_TRUE; } static void SDL_QuitMainThread(void) { - if (!SDL_main_thread_initialized) { - return; - } - SDL_QuitProperties(); SDL_QuitLog(); SDL_QuitFilesystem(); SDL_QuitTicks(); SDL_QuitTLSData(); - - SDL_main_thread_initialized = SDL_FALSE; } int SDL_InitSubSystem(SDL_InitFlags flags) diff --git a/src/SDL_log.c b/src/SDL_log.c index eef32b3508..b3d6028a01 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -118,6 +118,7 @@ void SDL_InitLog(void) void SDL_QuitLog(void) { SDL_ResetLogPriorities(); + if (log_function_mutex) { SDL_DestroyMutex(log_function_mutex); log_function_mutex = NULL;