Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the suppressed leaks mean in Valgrind?

Tags:

c

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.

like image 528
Genba Avatar asked Dec 28 '11 14:12

Genba


People also ask

What are suppressed errors Valgrind?

Therefore, Valgrind allows you to selectively suppress errors, by recording them in a suppressions file which is read when Valgrind starts up. The build mechanism attempts to select suppressions which give reasonable behaviour for the libc and XFree86 versions detected on your machine.

What is leak summary in Valgrind?

Valgrind reports two types of issues: memory errors and memory leaks. When a program dynamically allocates memory and forgets to later free it, it creates a leak. A memory leak generally won't cause a program to misbehave, crash, or give wrong answers, and is not an urgent situation.

What does indirectly lost mean in Valgrind?

"indirectly lost" means your program is leaking memory in a pointer-based structure. (E.g. if the root node of a binary tree is "definitely lost", all the children will be "indirectly lost".) If you fix the "definitely lost" leaks, the "indirectly lost" leaks should go away.


1 Answers

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.

like image 173
cnicutar Avatar answered Oct 21 '22 05:10

cnicutar