[SDL] Memory leak when intializing SDL for OpenGL on Linux.

c_lin colin3404 at gmail.com
Sat Dec 1 23:48:47 PST 2007


Here is my code:
---------------------------------------------------------------	
SDL_Init(SDL_INIT_VIDEO);

SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

int flags = SDL_OPENGL | SDL_ANYFORMAT;

SDL_SetVideoMode(800, 600, bpp, flags)

SDL_ShowCursor(SDL_DISABLE);

SDL_Quit();
---------------------------------------------------------------	

When I run this in valgrind (memory leak catcher) is reports the following:
---------------------------------------------------------------	
==10342== Invalid read of size 4
==10342==    at 0x4014C20: (within /lib/ld-2.6.1.so)
==10342==    by 0x4005BE9: (within /lib/ld-2.6.1.so)
==10342==    by 0x4007A07: (within /lib/ld-2.6.1.so)
==10342==    by 0x4010F83: (within /lib/ld-2.6.1.so)
==10342==    by 0x400D015: (within /lib/ld-2.6.1.so)
==10342==    by 0x401099D: (within /lib/ld-2.6.1.so)
==10342==    by 0x4DC9C18: (within /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x400D015: (within /lib/ld-2.6.1.so)
==10342==    by 0x4DCA2BB: (within /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x4DC9B50: dlopen (in /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x417C1DC: SDL_LoadObject (in /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x41802FE: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==  Address 0x4FBFC68 is 24 bytes inside a block of size 25 alloc'd
==10342==    at 0x4022765: malloc (vg_replace_malloc.c:149)
==10342==    by 0x4007FA1: (within /lib/ld-2.6.1.so)
==10342==    by 0x4010F83: (within /lib/ld-2.6.1.so)
==10342==    by 0x400D015: (within /lib/ld-2.6.1.so)
==10342==    by 0x401099D: (within /lib/ld-2.6.1.so)
==10342==    by 0x4DC9C18: (within /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x400D015: (within /lib/ld-2.6.1.so)
==10342==    by 0x4DCA2BB: (within /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x4DC9B50: dlopen (in /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x417C1DC: SDL_LoadObject (in /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x41802FE: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x418989B: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342== 
==10342== Invalid read of size 4
==10342==    at 0x4014C20: (within /lib/ld-2.6.1.so)
==10342==    by 0x400D319: (within /lib/ld-2.6.1.so)
==10342==    by 0x4009826: (within /lib/ld-2.6.1.so)
==10342==    by 0x4401464: (within /lib/tls/i686/cmov/libc-2.6.1.so)
==10342==    by 0x44017F9: _dl_sym (in /lib/tls/i686/cmov/libc-2.6.1.so)
==10342==    by 0x4DC9DE7: (within /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x400D015: (within /lib/ld-2.6.1.so)
==10342==    by 0x4DCA2BB: (within /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x4DC9D72: dlsym (in /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x417C11A: SDL_LoadFunction (in
/usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x417FCBC: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4180DE7: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==  Address 0x4FBFC68 is 24 bytes inside a block of size 25 alloc'd
==10342==    at 0x4022765: malloc (vg_replace_malloc.c:149)
==10342==    by 0x4007FA1: (within /lib/ld-2.6.1.so)
==10342==    by 0x4010F83: (within /lib/ld-2.6.1.so)
==10342==    by 0x400D015: (within /lib/ld-2.6.1.so)
==10342==    by 0x401099D: (within /lib/ld-2.6.1.so)
==10342==    by 0x4DC9C18: (within /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x400D015: (within /lib/ld-2.6.1.so)
==10342==    by 0x4DCA2BB: (within /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x4DC9B50: dlopen (in /lib/tls/i686/cmov/libdl-2.6.1.so)
==10342==    by 0x417C1DC: SDL_LoadObject (in /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x41802FE: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x418989B: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342== 
==10342== Syscall param write(buf) points to uninitialised byte(s)
==10342==    at 0x40007F2: (within /lib/ld-2.6.1.so)
==10342==    by 0x4D1E67E: _X11TransWrite (in /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4D164D6: (within /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4D165AA: _XReply (in /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4CFF591: XInternAtom (in /usr/lib/libX11.so.6.2.0)
==10342==    by 0x417E8CB: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x418A1B5: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4188AB3: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4189B99: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4178C50: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x414B780: SDL_InitSubSystem (in
/usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x414B7C6: SDL_Init (in /usr/lib/libSDL-1.2.so.0.11.0)
==10342==  Address 0x4FD0C4E is 14 bytes inside a block of size 16,384
alloc'd
==10342==    at 0x4021AA4: calloc (vg_replace_malloc.c:279)
==10342==    by 0x4D04326: XOpenDisplay (in /usr/lib/libX11.so.6.2.0)
==10342==    by 0x417EB3D: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4189957: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4178C50: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x414B780: SDL_InitSubSystem (in
/usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x414B7C6: SDL_Init (in /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x804D0FE: main (main.cpp:7)
==10342== 
==10342== Invalid read of size 4
==10342==    at 0x4063D76: (within /usr/lib/libGL.so.1.0.9639)
==10342==  Address 0x506F3B0 is 3,008 bytes inside a block of size 3,010
alloc'd
==10342==    at 0x4022765: malloc (vg_replace_malloc.c:149)
==10342==    by 0x40628B9: (within /usr/lib/libGL.so.1.0.9639)
==10342== 
==10342== Invalid read of size 4
==10342==    at 0x4063DDE: (within /usr/lib/libGL.so.1.0.9639)
==10342==  Address 0x506F3B0 is 3,008 bytes inside a block of size 3,010
alloc'd
==10342==    at 0x4022765: malloc (vg_replace_malloc.c:149)
==10342==    by 0x40628B9: (within /usr/lib/libGL.so.1.0.9639)
==10342== 
==10342== Invalid read of size 4
==10342==    at 0x4063EDB: (within /usr/lib/libGL.so.1.0.9639)
==10342==  Address 0x5070BA0 is 3,008 bytes inside a block of size 3,010
alloc'd
==10342==    at 0x4022765: malloc (vg_replace_malloc.c:149)
==10342==    by 0x40628B9: (within /usr/lib/libGL.so.1.0.9639)
==10342== 
==10342== Invalid read of size 4
==10342==    at 0x4072F7F: (within /usr/lib/libGL.so.1.0.9639)
==10342==  Address 0x512A968 is 208 bytes inside a block of size 209 alloc'd
==10342==    at 0x4022765: malloc (vg_replace_malloc.c:149)
==10342==    by 0x40732C1: (within /usr/lib/libGL.so.1.0.9639)
==10342==    by 0x41833DD: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4189038: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4177D32: SDL_SetVideoMode (in
/usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x804D0FE: main (main.cpp:7)
-
==10342== 
==10342== ERROR SUMMARY: 82 errors from 8 contexts (suppressed: 250 from 1)
==10342== malloc/free: in use at exit: 52,046 bytes in 442 blocks.
==10342== malloc/free: 8,878 allocs, 8,436 frees, 2,108,469 bytes allocated.
==10342== For counts of detected errors, rerun with: -v
==10342== searching for pointers to 442 not-freed blocks.
==10342== checked 795,280 bytes.
==10342== 
==10342== 
==10342== 28 bytes in 2 blocks are definitely lost in loss record 21 of 65
==10342==    at 0x4022765: malloc (vg_replace_malloc.c:149)
==10342==    by 0x4D491D2: (within /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4D480E6: (within /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4D49473: _XimSetICValueData (in /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4D42270: _XimLocalCreateIC (in /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4D26B4B: XCreateIC (in /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4188C70: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4188FFE: (within /usr/lib/libSDL-1.2.so.0.11.0)
==10342==    by 0x4177D32: SDL_SetVideoMode (in
/usr/lib/libSDL-1.2.so.0.11.0)
==10342== 
==10342== 
==10342== 400 bytes in 1 blocks are definitely lost in loss record 51 of 65
==10342==    at 0x4022765: malloc (vg_replace_malloc.c:149)
==10342==    by 0x4D12431: XGetVisualInfo (in /usr/lib/libX11.so.6.2.0)
==10342==    by 0x4067EF4: glXChooseVisual (in /usr/lib/libGL.so.1.0.9639)
==10342==    by 0x77: ???
==10342== 
==10342== LEAK SUMMARY:
==10342==    definitely lost: 428 bytes in 3 blocks.
==10342==      possibly lost: 0 bytes in 0 blocks.
==10342==    still reachable: 51,618 bytes in 439 blocks.
==10342==         suppressed: 0 bytes in 0 blocks.
---------------------------------------------------------------	

I have a hard time believing that SDL is leaking memory, so I'm assuming I'm
doing something wrong in my code, or valgrind is claiming false data.

If anyone could help me out that would be great.
-- 
View this message in context: http://www.nabble.com/Memory-leak-when-intializing-SDL-for-OpenGL-on-Linux.-tf4930815.html#a14113271
Sent from the SDL mailing list archive at Nabble.com.




More information about the SDL mailing list