Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
770 views
in Technique[技术] by (71.8m points)

c - What do the suppressed leaks mean in Valgrind?

I have developed a pure-C implementation of FIFO lists (queues) in files fifo.h and fifo.c, and have written a test programme testfifo.c which I compile to ./bin/testfifo. The node structure is defined in list.h.

I run my programme through Valgrind on OS X 10.6 like this

valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./bin/testfifo

and get the following output

==54688== Memcheck, a memory error detector
==54688== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==54688== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==54688== Command: bin/testfifo
==54688== 
--54688-- bin/testfifo:
--54688-- dSYM directory is missing; consider using --dsymutil=yes
==54688== 
==54688== HEAP SUMMARY:
==54688==     in use at exit: 88 bytes in 1 blocks
==54688==   total heap usage: 11 allocs, 10 frees, 248 bytes allocated
==54688== 
==54688== LEAK SUMMARY:
==54688==    definitely lost: 0 bytes in 0 blocks
==54688==    indirectly lost: 0 bytes in 0 blocks
==54688==      possibly lost: 0 bytes in 0 blocks
==54688==    still reachable: 0 bytes in 0 blocks
==54688==         suppressed: 88 bytes in 1 blocks
==54688== 
==54688== For counts of detected and suppressed errors, rerun with: -v
==54688== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

According to the leak summary, there are no leaks, but I am still wondering what the "suppressed" leaks are. Besides, the number of alloc's and free's do not match, and hence I am unsure if there are leaks or not.

----EDIT----

Running

valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v ./bin/testfifo

on OS X 10.6 produces a quite long and confusing output, but I have run

valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./bin/testfifo

on a Linux machine an got this output:

==32688== Memcheck, a memory error detector
==32688== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==32688== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==32688== Command: bin/testfifo
==32688== 
==32688== 
==32688== HEAP SUMMARY:
==32688==     in use at exit: 0 bytes in 0 blocks
==32688==   total heap usage: 10 allocs, 10 frees, 160 bytes allocated
==32688== 
==32688== All heap blocks were freed -- no leaks are possible
==32688== 
==32688== For counts of detected and suppressed errors, rerun with: -v
==32688== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

alloc's and free's now match, so the extra alloc on OS X seems to be due to some system library, as has been suggested.

I have run the very same command with the -v option, in order to reveal the 4 suppressed errors, but I have not got any easily understandable new information.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Those are leaks outside of your code, in (probably shared) libraries or known false positives. Running valgrind with -v should inform you about the suppressions used.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...