Why sdl is reported memory leak by valgrind

hello guys:

sdl-config --version: 1.2.13
valgrind --version : valgrind-3.2.3

this is a simple test about sdl (sdltest.c):

#include <SDL/SDL.h>

int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO);
SDL_Quit();
}

then i compiled sdltest.c:
gcc -g -o sdltest sdltest.c -lSDL

next, i run it with valgrind:

valgrind --tool=memcheck --leak-check=full --show-reachable=yes
–error-limit=no ./sdltest

then valgrind report some memory leak error:

==19611== 16 bytes in 2 blocks are definitely lost in loss record 9 of 55
==19611== at 0x4005525: malloc (vg_replace_malloc.c:149)
==19611== by 0xA9F882: (within /usr/lib/libX11.so.6.2.0)
==19611== by 0xA9E0D6: (within /usr/lib/libX11.so.6.2.0)
==19611== by 0xA9F063: _XimSetICValueData (in /usr/lib/libX11.so.6.2.0)
==19611== by 0xAA50D0: _XimLocalCreateIC (in /usr/lib/libX11.so.6.2.0)
==19611== by 0xA8CD7B: XCreateIC (in /usr/lib/libX11.so.6.2.0)
==19611== by 0x619E740: create_aux_windows (SDL_x11video.c:515)
==19611== by 0x619F924: X11_VideoInit (SDL_x11video.c:682)
==19611== by 0x618C5AD: SDL_VideoInit (SDL_video.c:240)
==19611== by 0x615F390: SDL_InitSubSystem (SDL.c:70)
==19611== by 0x615F3D6: SDL_Init (SDL.c:162)
==19611== by 0x80484E0: main (sdltest.c:5)

==19611== 224 (16 direct, 208 indirect) bytes in 2 blocks are definitely
lost in loss record 21 of 55
==19611== at 0x4005622: realloc (vg_replace_malloc.c:306)
==19611== by 0xA92B83: (within /usr/lib/libX11.so.6.2.0)
==19611== by 0xA9371B: (within /usr/lib/libX11.so.6.2.0)
==19611== by 0xA95677: _XlcCreateLC (in /usr/lib/libX11.so.6.2.0)
==19611== by 0xAB3AFA: _XlcDefaultLoader (in /usr/lib/libX11.so.6.2.0)
==19611== by 0xA9BFD2: _XOpenLC (in /usr/lib/libX11.so.6.2.0)
==19611== by 0xA9C112: _XlcCurrentLC (in /usr/lib/libX11.so.6.2.0)
==19611== by 0xA9C5C0: XSetLocaleModifiers (in /usr/lib/libX11.so.6.2.0)
==19611== by 0x6194EBD: XSetLocaleModifiers (SDL_x11sym.h:149)
==19611== by 0x619E8E9: create_aux_windows (SDL_x11video.c:468)
==19611== by 0x619F924: X11_VideoInit (SDL_x11video.c:682)
==19611== by 0x618C5AD: SDL_VideoInit (SDL_video.c:240)

now this report made by valgrind is true or false. i have read the
corresponding source code in SDL, maybe there exist some question
that maybe cause memory leak?

so i want to know there is or not some resource allocated by SDL_Init is not
release by SDL_Quit?

thanks.

then valgrind report some memory leak error:

It’s a leak in Xlib, even if we properly clean up the subsystem that
allocated the memory.

–ryan.

thanks for your response. maybe this leak exist in many versions of Xlib,
why it hasn’t been corrected.

2008/5/19, Ryan C. Gordon :>

then valgrind report some memory leak error:

It’s a leak in Xlib, even if we properly clean up the subsystem that
allocated the memory.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

hi,

Maybe a bug hasn’t been reported?

http://bugs.xfree86.org/
https://bugs.freedesktop.org/On Tue, May 20, 2008 at 11:37 AM, Tao Yu wrote:

thanks for your response. maybe this leak exist in many versions of Xlib,
why it hasn’t been corrected.

2008/5/19, Ryan C. Gordon :

then valgrind report some memory leak error:

It’s a leak in Xlib, even if we properly clean up the subsystem that
allocated the memory.

–ryan.

Not sure about this instance, but if it’s in exit/cleanup code, then the
resources are auto-reclaimed by OS, so people tend to be lazy with it…

Also, some leaks, aren’t leaks - see the Valgrind documentation.
Basically, Valgrind isn’t perfect and may sometimes incorrectly report
leaks due to the complexity of the software.

This isn’t a cop-out, it’s just a matter-of-fact. Valgrind provides
facilities to suppress these errors.

Incidentally, the total memory lost is 240 bytes, so it’s probably a
one-of allocation that isn’t freed. If that’s the most your program ever
leaks, I wouldn’t worry about it (as it’s re-claimed by the OS anyway…)

If it were 1MB or more, then it would more likely be a repeat-allocate
without free, which is serious (as this will eventually cause heap
exhaustion), as it could lead to your program failing.

Eddy

Tao Yu wrote:> thanks for your response. maybe this leak exist in many versions of

Xlib, why it hasn’t been corrected.

2008/5/19, Ryan C. Gordon <icculus at icculus.org
<mailto:icculus at icculus.org>>:

    then valgrind report some memory leak error:


It's a leak in Xlib, even if we properly clean up the subsystem that
allocated the memory.

--ryan.


_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org