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 on quit because SDL_TLSCleanup isn't called on the main thread #2804

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

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.7
Reported for operating system, platform: Windows 10, x86_64

Comments on the original bug report:

On 2018-01-19 17:46:34 +0000, Jack Powell wrote:

SDL leaks memory on quit of the application. This can be found out by using Microsoft's built in CRT leak detection.

I fixed the leaks in my build of SDL by simply adding a call to SDL_TLSCleanup in SDL_Quit. The issue is thread-local storage is not cleaned up for the main thread. Because of my complex requirements I have made SDL_TLSCleanup a public function which would be something I think would be good for advanced users.

The leak you'll notice in SDL is the error string since it is TLS! The memory won't get freed until SDL_TLSCleanup is called so adding the call in SDL_Quit seems like a perfect solution for main thread quitting although maybe just incase the function should be exported and the winmain/main wrapper should call SDL_TLSCleanup (the one that calls SDL_SetMainReady)?

I've flagged this as major since the TLS not being cleaned up can cause issues where important cleanup is not done such as flushing settings or open data handles. This could cause loss or corruption of data in some applications.

Bug "3317 Memory Leak in SDL_SetError when using std::thread" may also relate to this. Adding SDL_TLSCleanup as an exported/public function would resolve third party threading such as std::thread as one could simply call SDL_TLSCleanup once the thread quits. Although applications using SDL should use SDL's create thread in my opinion.

Many Thanks
Jack Powell

On 2020-03-25 00:25:06 +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