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 426

Summary: SDL_Init() and memory leak
Product: SDL Reporter: vanpie <vanpie>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P1    
Version: HG 1.2   
Hardware: x86   
OS: Linux   
URL: http://www.vanpie.be

Description vanpie 2007-05-08 06:31:38 UTC
Sorry for my English, but I'm Belgian. 

I thinks had discover a little memory leak with the SDL_Init() function. I run on Ubuntu 7.04 and i develops a game with SDL libraries and C language.

These following lines are the return of valgrind:
==9420==  Address 0x47DD056 is 14 bytes inside a block of size 16,384 alloc'd
==9420==    at 0x402095F: calloc (vg_replace_malloc.c:279)
==9420==    by 0x45EE346: XOpenDisplay (in /usr/lib/libX11.so.6.2.0)
==9420==    by 0x4093BED: (within /usr/lib/libSDL-1.2.so.0.11.0)
==9420==    by 0x409E987: (within /usr/lib/libSDL-1.2.so.0.11.0)
==9420==    by 0x408B8B0: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.0)
==9420==    by 0x405E1D0: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.0)
==9420==    by 0x405E216: SDL_Init (in /usr/lib/libSDL-1.2.so.0.11.0)
==9420==    by 0x8048FF4: main (main.c:5)
....
==9420== LEAK SUMMARY:
==9420==    definitely lost: 10 bytes in 2 blocks.
==9420==      possibly lost: 0 bytes in 0 blocks.
==9420==    still reachable: 23,249 bytes in 393 blocks.
==9420==         suppressed: 0 bytes in 0 blocks.


My very simplified C code:
#include <SDL/SDL.h>

int main (){
  atexit(SDL_Quit);

  if ((SDL_Init(SDL_INIT_VIDEO)) == -1){ //line 5
    fprintf(stderr,"Error at SDL_Init  : %s\n",SDL_GetError());
    return -1;
  }
 
  SDL_Quit();
  return 0;
}
Comment 1 Ryan C. Gordon 2007-06-02 13:59:02 UTC
Bumping a bunch of bugs to Priority 1 for consideration for the 1.2.12 release.

--ryan.

Comment 2 Ryan C. Gordon 2007-06-15 00:00:19 UTC
This leak could be inside Xlib...it doesn't happen here with your test program and Valgrind.

However, I could see an unlikely case where SDL_Init() fails that might leak in that sort of way, and I've committed a patch for it in svn revision #3075 for the 1.2 branch (this patch doesn't apply to the 1.3 branch).

--ryan.