mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-23 11:38:28 +00:00
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.
This commit is contained in:
13
src/SDL.c
13
src/SDL.c
@@ -113,7 +113,6 @@ static SDL_bool SDL_MainIsReady = SDL_FALSE;
|
|||||||
#else
|
#else
|
||||||
static SDL_bool SDL_MainIsReady = SDL_TRUE;
|
static SDL_bool SDL_MainIsReady = SDL_TRUE;
|
||||||
#endif
|
#endif
|
||||||
static SDL_bool SDL_main_thread_initialized = SDL_FALSE;
|
|
||||||
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
|
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
|
||||||
static Uint8 SDL_SubsystemRefCount[32];
|
static Uint8 SDL_SubsystemRefCount[32];
|
||||||
|
|
||||||
@@ -186,33 +185,21 @@ void SDL_SetMainReady(void)
|
|||||||
/* Initialize all the subsystems that require initialization before threads start */
|
/* Initialize all the subsystems that require initialization before threads start */
|
||||||
void SDL_InitMainThread(void)
|
void SDL_InitMainThread(void)
|
||||||
{
|
{
|
||||||
if (SDL_main_thread_initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_InitTLSData();
|
SDL_InitTLSData();
|
||||||
SDL_InitTicks();
|
SDL_InitTicks();
|
||||||
SDL_InitFilesystem();
|
SDL_InitFilesystem();
|
||||||
SDL_InitLog();
|
SDL_InitLog();
|
||||||
SDL_InitProperties();
|
SDL_InitProperties();
|
||||||
SDL_GetGlobalProperties();
|
SDL_GetGlobalProperties();
|
||||||
|
|
||||||
SDL_main_thread_initialized = SDL_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SDL_QuitMainThread(void)
|
static void SDL_QuitMainThread(void)
|
||||||
{
|
{
|
||||||
if (!SDL_main_thread_initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_QuitProperties();
|
SDL_QuitProperties();
|
||||||
SDL_QuitLog();
|
SDL_QuitLog();
|
||||||
SDL_QuitFilesystem();
|
SDL_QuitFilesystem();
|
||||||
SDL_QuitTicks();
|
SDL_QuitTicks();
|
||||||
SDL_QuitTLSData();
|
SDL_QuitTLSData();
|
||||||
|
|
||||||
SDL_main_thread_initialized = SDL_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int SDL_InitSubSystem(SDL_InitFlags flags)
|
int SDL_InitSubSystem(SDL_InitFlags flags)
|
||||||
|
@@ -118,6 +118,7 @@ void SDL_InitLog(void)
|
|||||||
void SDL_QuitLog(void)
|
void SDL_QuitLog(void)
|
||||||
{
|
{
|
||||||
SDL_ResetLogPriorities();
|
SDL_ResetLogPriorities();
|
||||||
|
|
||||||
if (log_function_mutex) {
|
if (log_function_mutex) {
|
||||||
SDL_DestroyMutex(log_function_mutex);
|
SDL_DestroyMutex(log_function_mutex);
|
||||||
log_function_mutex = NULL;
|
log_function_mutex = NULL;
|
||||||
|
Reference in New Issue
Block a user