Skip to content

Commit

Permalink
Fix libsdl-org#3596, free all TLS data at the end of SDL_Quit to av…
Browse files Browse the repository at this point in the history
…oid memory leak
  • Loading branch information
jixingcn committed Mar 16, 2021
1 parent 108bb5a commit ce00b4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SDL.c
Expand Up @@ -447,6 +447,9 @@ SDL_Quit(void)
*/
SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );

/* Cleanup all TLS data */
SDL_Generic_CleanupAllTLSData();

SDL_bInMainQuit = SDL_FALSE;
}

Expand Down
6 changes: 6 additions & 0 deletions src/thread/SDL_thread.c
Expand Up @@ -200,6 +200,12 @@ SDL_Generic_SetTLSData(SDL_TLSData *storage)
return 0;
}

void
SDL_Generic_CleanupAllTLSData(void)
{
SDL_TLSCleanup();
}

/* Routine to get the thread-specific error variable */
SDL_error *
SDL_GetErrBuf(void)
Expand Down
3 changes: 3 additions & 0 deletions src/thread/SDL_thread_c.h
Expand Up @@ -97,6 +97,9 @@ extern SDL_TLSData *SDL_Generic_GetTLSData(void);
*/
extern int SDL_Generic_SetTLSData(SDL_TLSData *data);

/* Cleanup all TLS data for this thread. */
extern void SDL_Generic_CleanupAllTLSData(void);

#endif /* SDL_thread_c_h_ */

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit ce00b4e

Please sign in to comment.