Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak in SDL_SetError when using std::thread #2149

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

Memory Leak in SDL_SetError when using std::thread #2149

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Labels
duplicate This issue or pull request already exists

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.1
Reported for operating system, platform: Mac OS X (All), x86_64

Comments on the original bug report:

On 2016-05-03 20:46:25 +0000, Diego wrote:

Created attachment 2438
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

On 2017-08-12 03:44:10 +0000, Sam Lantinga wrote:

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.

On 2020-03-05 08:19:59 +0000, wrote:

SDL_Quit() doesn't call it either.

On 2020-03-05 09:38:53 +0000, wrote:

// (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()

On 2020-03-05 09:46:53 +0000, wrote:

exposing SDL_TLSCleanup() via an extern, instead of it being static, then calling it in SDL_Quit() clears up my variant of the problem.

On 2020-03-17 08:58:32 +0000, wrote:

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

On 2020-03-25 00:24:40 +0000, Ryan C. Gordon wrote:

Consolidating this with Bug # 5041.

*** This bug has been marked as a duplicate of bug 5041 ***

@SDLBugzilla SDLBugzilla added bug duplicate This issue or pull request already exists labels Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

1 participant