Hi Everyone,
Here is a simple X application that has memory leaks.
void SimpleXTest(){
XtAppContext appContext = NULL;Widget mainWidget = NULL;// ------------------------------------------------//int argc = 3;//Num of argschar* argv[] ={"SimpleXTest","-display",":0.0",NULL};mainWidget = XtVaAppInitialize(&appContext,"Demos",NULL,0,&argc,argv,NULL,NULL);XtRealizeWidget(mainWidget);XtAppMainLoop(appContext);XtDestroyWidget(mainWidget);XtDestroyApplicationContext(appContext);
}
Valgrind reports:
==8068==
==8068== HEAP SUMMARY:
==8068== in use at exit: 175,474 bytes in 2,076 blocks
==8068== total heap usage: 2,987 allocs, 911 frees, 309,301 bytes allocated
==8068==
==8068== LEAK SUMMARY:
==8068== definitely lost: 0 bytes in 0 blocks
==8068== indirectly lost: 0 bytes in 0 blocks
==8068== possibly lost: 1,232 bytes in 51 blocks
==8068== still reachable: 174,242 bytes in 2,025 blocks
==8068== suppressed: 0 bytes in 0 blocks
==8068== Rerun with --leak-check=full to see details of leaked memory
==8068==
==8068== For counts of detected and suppressed errors, rerun with: -v
==8068== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 3)
I am under the impression that I can't use Valgrind with X to detect if my X application is leaking. Or, what am I misunderstanding?
Thanks,
Jason
JasonCA wrote:
I am under the impression that I can't use Valgrind with X to detect if my X application is leaking. Or, what am I misunderstanding?
==8068== definitely lost: 0 bytes in 0 blocks
==8068== indirectly lost: 0 bytes in 0 blocks
I don't see a definite leak anywhere in Valgrind's report.
Valgrind does have some false positives, so
==8068== possibly lost: 1,232 bytes in 51 blocks
is not a casue for great concern.
I am using Valgrind on my X/Motif programs with good results.
Hi Peter,
Thanks for your response as I do appreciate it.
So these are not leaks?:
==6186==
==6186== HEAP SUMMARY:
==6186== in use at exit: 175,370 bytes in 2,075 blocks
==6186== total heap usage: 2,990 allocs, 915 frees, 309,229 bytes allocated
==6186==
==6186== 6 bytes in 1 blocks are possibly lost in loss record 23 of 517
==6186== at 0x402860A: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==6186== by 0x43E090F: XInitExtension (in /usr/lib/libX11.so.6.3.0)
==6186== by 0x4853F47: XextAddDisplay (in /usr/lib/libXext.so.6.4.0)
==6186== by 0x484DE25: ??? (in /usr/lib/libXext.so.6.4.0)
==6186== by 0x484E03B: XShapeQueryExtension (in /usr/lib/libXext.so.6.4.0)
==6186== by 0x41A396E: ??? (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x4302DEF: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x43037F4: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x4304387: _XtAppCreateShell (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x4304541: XtAppCreateShell (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x41A368B: ??? (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x41A3F34: XmGetXmDisplay (in /usr/lib/libXm.so.4.0.2)
[...additional leaks reported here ...]
==6186== 72 bytes in 1 blocks are possibly lost in loss record 403 of 517
==6186== at 0x40270BB: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==6186== by 0x43E09F0: XAddExtension (in /usr/lib/libX11.so.6.3.0)
==6186== by 0x4031EDA: _XcursorGetDisplayInfo (in /usr/lib/libXcursor.so.1.0.2)
==6186== by 0x403243A: XcursorSupportsARGB (in /usr/lib/libXcursor.so.1.0.2)
==6186== by 0x4034EF3: XcursorTryShapeCursor (in /usr/lib/libXcursor.so.1.0.2)
==6186== by 0x43D404F: XCreateGlyphCursor (in /usr/lib/libX11.so.6.3.0)
==6186== by 0x43D458A: XCreateFontCursor (in /usr/lib/libX11.so.6.3.0)
==6186== by 0x4301284: XtCvtStringToCursor (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x42FC2F7: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x42FD28F: _XtConvert (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x431ABBB: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x431BA90: _XtGetResources (in /usr/lib/libXt.so.6.0.0)
==6186==
==6186== 72 bytes in 1 blocks are possibly lost in loss record 404 of 517
==6186== at 0x40270BB: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==6186== by 0x43E08E8: XInitExtension (in /usr/lib/libX11.so.6.3.0)
==6186== by 0x4A0E61F: XRenderFindDisplay (in /usr/lib/libXrender.so.1.3.0)
==6186== by 0x4A0E96A: XRenderQueryExtension (in /usr/lib/libXrender.so.1.3.0)
==6186== by 0x4031F2B: _XcursorGetDisplayInfo (in /usr/lib/libXcursor.so.1.0.2)
==6186== by 0x403243A: XcursorSupportsARGB (in /usr/lib/libXcursor.so.1.0.2)
==6186== by 0x4034EF3: XcursorTryShapeCursor (in /usr/lib/libXcursor.so.1.0.2)
==6186== by 0x43D404F: XCreateGlyphCursor (in /usr/lib/libX11.so.6.3.0)
==6186== by 0x43D458A: XCreateFontCursor (in /usr/lib/libX11.so.6.3.0)
==6186== by 0x4301284: XtCvtStringToCursor (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x42FC2F7: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x42FD28F: _XtConvert (in /usr/lib/libXt.so.6.0.0)
==6186==
==6186== 112 bytes in 1 blocks are possibly lost in loss record 425 of 517
==6186== at 0x402860A: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==6186== by 0x43D39B0: XCreateGC (in /usr/lib/libX11.so.6.3.0)
==6186== by 0x40D5976: _XmGetScaledPixmap (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x40D5D38: XmGetScaledPixmap (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x41C5317: ??? (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x42FC51E: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x42FD28F: _XtConvert (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x431ABBB: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x431BA90: _XtGetResources (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x4303744: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x4303C83: _XtCreateWidget (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x4303F95: XtCreateWidget (in /usr/lib/libXt.so.6.0.0)
==6186==
==6186== 340 bytes in 17 blocks are possibly lost in loss record 465 of 517
==6186== at 0x402860A: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==6186== by 0x42F9EF0: XtMalloc (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x40D3093: ??? (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x40D3ED0: ??? (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x40D547F: _XmGetScaledPixmap (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x40D5D38: XmGetScaledPixmap (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x41C5317: ??? (in /usr/lib/libXm.so.4.0.2)
==6186== by 0x42FC51E: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x42FD28F: _XtConvert (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x431ABBB: ??? (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x431BA90: _XtGetResources (in /usr/lib/libXt.so.6.0.0)
==6186== by 0x4303744: ??? (in /usr/lib/libXt.so.6.0.0)
==6186==
==6186== LEAK SUMMARY:
==6186== definitely lost: 0 bytes in 0 blocks
==6186== indirectly lost: 0 bytes in 0 blocks
==6186== possibly lost: 1,232 bytes in 51 blocks
==6186== still reachable: 174,138 bytes in 2,024 blocks
==6186== suppressed: 0 bytes in 0 blocks
==6186== Reachable blocks (those to which a pointer was found) are not shown.
==6186== To see them, rerun with: --leak-check=full --show-reachable=yes
==6186==
==6186== For counts of detected and suppressed errors, rerun with: -v
==6186== ERROR SUMMARY: 35 errors from 35 contexts (suppressed: 3 from 3)
So I am assuming then that I should not worry so much about the "possibly lost"? After reading the Valgrind documentation, I was of the understanding that "possibly lost" are still allocating that are most likely lost.
Otherwise, perhaps this is all that I really need to worry about:
==6186== definitely lost: 0 bytes in 0 blocks
==6186== indirectly lost: 0 bytes in 0 blocks
Could you clarify.
Again, thanks! :)
Jason
All the errors appear to be in the libraries, not in your code.
When it is in your code, and it is properly compiled with debug options, you will see the line numbers next to function call.
You may wish to try an older version of Valgrind, 3.4.1, instead of the current 3.5, since 3.5 does report huge numbers of false positives in X related code, in my experience.