We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3339

Summary: Memory leak from glXChooseFBConfig
Product: SDL Reporter: Zach <mikezackles>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.4   
Hardware: x86_64   
OS: Linux   
Attachments: Free the list returned by glXFBChooseConfig

Description Zach 2016-05-20 17:55:11 UTC
Created attachment 2459 [details]
Free the list returned by glXFBChooseConfig

This might be a dupe of bug 2539, but that bug is a couple of years old, and the problem and solution seem a lot simpler to me than described there.

I noticed that Clang's address sanitizer reports a leak after proper creation and destruction of an OpenGL ES v3 context on X using the system copy of SDL, version 2.0.4, on Arch Linux. It appears that this can be traced to the failure to free the list of configs returned by glXFBChooseConfig.

bug 2539 is correct in pointing out that the docs for glXFBChooseConfig indicate that the returned memory should be freed using XFree. This call returns a list of pointers to configs, and I believe the actual config structs are managed internally. (I did a bit of tracing in mesa to convince myself of this.) This would imply that the list can be freed immediately, making this a one-liner.

As further evidence, note that in the OpenGL Wiki code sample below the config list is freed before the config is even used:
https://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX)

So anyway, I've attached a patch. I've confirmed that linking against the patched version eliminates the leak on my system. Apologies if I'm horribly mistaken, and thanks for maintaining!
Comment 1 Sam Lantinga 2017-08-12 02:38:07 UTC
This is fixed in Mercurial, thanks!
Comment 2 Zach 2017-08-13 00:29:38 UTC
Great!