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 2493 - Memory leak on simplest possible example
Summary: Memory leak on simplest possible example
Status: RESOLVED DUPLICATE of bug 2086
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.2
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-12 08:44 UTC by jightuse
Modified: 2014-04-18 03:55 UTC (History)
0 users

See Also:


Attachments
minimal_example.c (96 bytes, text/plain)
2014-04-12 08:44 UTC, jightuse
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jightuse 2014-04-12 08:44:24 UTC
Created attachment 1617 [details]
minimal_example.c

I tried to found memory leaks in my project which uses SDL2 and C++11.
See this SO question https://stackoverflow.com/questions/23027862/memory-leak-on-object-destruction and this forum thread http://forums.libsdl.org/viewtopic.php?p=42979&sid=8cf1d6c83d4d73fe6cfbb7cbb16b3d28 (I have created an account on it but I "have no rights" to post something).

Some investigation shows that this minimal example (see attachment) triggers valgrind warnings:
$ valgrind --leak-check=full ./a.out                
==30569== Memcheck, a memory error detector
==30569== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==30569== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==30569== Command: ./a.out
==30569== 
==30569== 
==30569== HEAP SUMMARY:
==30569==     in use at exit: 76,368 bytes in 516 blocks
==30569==   total heap usage: 19,676 allocs, 19,160 frees, 44,888,606 bytes allocated
==30569== 
==30569== 12 bytes in 2 blocks are definitely lost in loss record 5 of 100
==30569==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==30569==    by 0x51B5829: strdup (strdup.c:42)
==30569==    by 0x6195666: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==30569==    by 0x6196474: _XimSetICValueData (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==30569==    by 0x6191A69: _XimLocalCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==30569==    by 0x6178044: XCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==30569==    by 0x4EEBCD2: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4EEC0F7: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4EDF5FF: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4EDF40F: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4E4A48E: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4006BA: main (dog.c:4)
==30569== 
==30569== 104 bytes in 1 blocks are definitely lost in loss record 58 of 100
==30569==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==30569==    by 0xBC79A11: ??? (in /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1.2.0)
==30569==    by 0xBC52600: ??? (in /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1.2.0)
==30569==    by 0xBC4EE7A: ??? (in /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1.2.0)
==30569==    by 0xBC4F60F: glXChooseVisual (in /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1.2.0)
==30569==    by 0x4EE8D0E: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4EE8F40: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4EDDB65: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4EDF6FB: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4EDF40F: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4E4A48E: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==30569==    by 0x4006BA: main (dog.c:4)
==30569== 
==30569== LEAK SUMMARY:
==30569==    definitely lost: 116 bytes in 3 blocks
==30569==    indirectly lost: 0 bytes in 0 blocks
==30569==      possibly lost: 0 bytes in 0 blocks
==30569==    still reachable: 76,252 bytes in 513 blocks
==30569==         suppressed: 0 bytes in 0 blocks
==30569== Reachable blocks (those to which a pointer was found) are not shown.
==30569== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==30569== 
==30569== For counts of detected and suppressed errors, rerun with: -v
==30569== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 6 from 3)
Comment 1 jightuse 2014-04-14 10:18:28 UTC
Stack trace with dbg packages installed:
$ valgrind --leak-check=full ./a.out
==11828== Memcheck, a memory error detector
==11828== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==11828== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==11828== Command: ./a.out
==11828== 

==11828== 
==11828== HEAP SUMMARY:
==11828==     in use at exit: 76,368 bytes in 516 blocks
==11828==   total heap usage: 19,239 allocs, 18,723 frees, 44,848,319 bytes allocated
==11828== 
==11828== 12 bytes in 2 blocks are definitely lost in loss record 5 of 100
==11828==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==11828==    by 0x51B5829: strdup (strdup.c:42)
==11828==    by 0x6195666: _XimEncodeString (imRm.c:818)
==11828==    by 0x6196474: _XimSetICValueData (imRm.c:2912)
==11828==    by 0x6191A69: _XimLocalCreateIC (imLcIc.c:176)
==11828==    by 0x6178044: XCreateIC (ICWrap.c:247)
==11828==    by 0x4EEBCD2: SetupWindowData (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4EEC0F7: X11_CreateWindow (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4EDF5FF: SDL_CreateWindow_REAL (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4EDF40F: SDL_VideoInit_REAL (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4E4A48E: SDL_InitSubSystem_REAL (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4006BA: main (minimal_example.c:4)
==11828== 
==11828== 104 bytes in 1 blocks are definitely lost in loss record 58 of 100
==11828==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==11828==    by 0xBC79A11: ??? (in /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1.2.0)
==11828==    by 0xBC52600: ??? (in /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1.2.0)
==11828==    by 0xBC4EE7A: ??? (in /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1.2.0)
==11828==    by 0xBC4F60F: glXChooseVisual (in /usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1.2.0)
==11828==    by 0x4EE8D0E: X11_GL_GetVisual (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4EE8F40: X11_GL_LoadLibrary (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4EDDB65: SDL_GL_LoadLibrary_REAL (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4EDF6FB: SDL_CreateWindow_REAL (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4EDF40F: SDL_VideoInit_REAL (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4E4A48E: SDL_InitSubSystem_REAL (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==11828==    by 0x4006BA: main (minimal_example.c:4)
==11828== 
==11828== LEAK SUMMARY:
==11828==    definitely lost: 116 bytes in 3 blocks
==11828==    indirectly lost: 0 bytes in 0 blocks
==11828==      possibly lost: 0 bytes in 0 blocks
==11828==    still reachable: 76,252 bytes in 513 blocks
==11828==         suppressed: 0 bytes in 0 blocks
==11828== Reachable blocks (those to which a pointer was found) are not shown.
==11828== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==11828== 
==11828== For counts of detected and suppressed errors, rerun with: -v
==11828== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 6 from 3)
Comment 2 Sam Lantinga 2014-04-18 03:55:07 UTC
This is a duplicate of bug 2086

*** This bug has been marked as a duplicate of bug 2086 ***