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 756

Summary: Memory leak in DirectDraw backend
Product: SDL Reporter: Steven Don <shd>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: 1.2.13Keywords: target-1.2.14
Hardware: x86   
OS: Windows (All)   
Attachments: Fix for memory leak

Description Steven Don 2009-06-20 14:33:05 UTC
Created attachment 333 [details]
Fix for memory leak

Certain codepaths in the DirectDraw backend for SDL 1.2 SDL_malloc a buffer which is never SDL_free'd. Instead, the pointer is simply overwritten by a pointer to a DirectDraw surface when the surface is locked. That is a memory leak.

The patch attached stores the pointer for later proper release.

I also posted this to the mailing list, and was directed to submit it here.
Comment 1 Sam Lantinga 2009-06-30 22:11:39 UTC
When does surface->pixels get allocated prior to DX5_LockHWSurface()?
Comment 2 Steven Don 2009-07-01 11:01:15 UTC
In SDL_SetVideoMode. The reason I've left it in and don't just SDL_Free it immediately on a lock is on the off-chance that some badly behaved program grabs the pointer immediately after SDL_SetVideoMode and uses it. Freeing it immediately or not allocating it at all would break compatibility with such programs. Personally I think that should be avoided if it can be helped.
Comment 3 Ryan C. Gordon 2009-09-13 16:33:01 UTC
Tagging this bug with "target-1.2.14" so we can try to resolve it for SDL 1.2.14.

Please note that we may choose to resolve it as WONTFIX. This tag is largely so we have a comprehensive wishlist of bugs to examine for 1.2.14 (and so we can close bugs that we'll never fix, rather than have them live forever in Bugzilla).

--ryan.
Comment 4 Sam Lantinga 2009-09-26 21:06:21 UTC
Can you give me a test case that reproduces the memory leak?  I'd like to fully understand what's going on before I apply this patch.

Thanks!
Comment 5 Sam Lantinga 2009-10-17 11:08:40 UTC
This is a risky change for SDL 1.2, so I'm going to hold off fixing it for now.  If you have a test case, please re-open this bug.

Thanks!