| Summary: | Memory Leak in SDL_SetError when using std::thread | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Diego <diegoacevedo91> |
| Component: | thread | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED DUPLICATE | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | icculus, sdlbugs |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Mac OS X (All) | ||
| See Also: | https://bugzilla.libsdl.org/show_bug.cgi?id=5041 | ||
| Attachments: | Leak producing code | ||
This is because SDL_TLSCleanup() doesn't get called and SDL doesn't link the C++ runtime and has no way to automatically call it at thread termination. In a future release we could export a thread cleanup function that could be called to take care of this. SDL_Quit() doesn't call it either. // (Sketch code of another repro case)
int main()
{
SDL_SetMainReady(); // Can do normal startup, but this is simplest case
SDL_Init(0);
SDL_Quit();
return 0;
} // Will leak memory allocated in SDL_ClearError()
exposing SDL_TLSCleanup() via an extern, instead of it being static, then calling it in SDL_Quit() clears up my variant of the problem. Reported as separate bug because it has a separate repro case, but linked to this one. https://bugzilla.libsdl.org/show_bug.cgi?id=5041 |
Created attachment 2438 [details] Leak producing code When SDL_SetError is called from a thread created using std::thread there are two memory leaks. One is caused by a malloc in SDL_GetErrBuf and the other is caused by a realloc in SDL_TLSSet. There are no leaks when using SDL_Thread, only when using std::thread. This is reported by using Instruments on my mac. I believe this is the compiler and related information: Apple LLVM version 7.3.0 (clang-703.0.29) Target: x86_64-apple-darwin15.4.0 Thread model: posix