Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error summary in Valgrind output?

I have seen some of the post regarding valgrind but not single post helped me in understanding interpretation of valgrind output. I ran two programs with valgrind (Both having memory leaks)

Sample Output for Test 1

==20422== LEAK SUMMARY:
==20422== definitely lost: 448 bytes in 3 blocks
==20422== indirectly lost: 786,460 bytes in 1 blocks
==20422== possibly lost: 1,576,052 bytes in 46 blocks
==20422== still reachable: 1,077,107 bytes in 2,333 blocks
==20422== suppressed: 0 bytes in 0 blocks
==20422== Rerun with --leak-check=full to see details of leaked memory
==20422==
==20422== For counts of detected and suppressed errors, rerun with: -v
==20422== ERROR SUMMARY: 98307 errors from 5 contexts (suppressed: 2 from 2)
Killed

Output for Test 2

==20875== HEAP SUMMARY:
==20875== in use at exit: 1,059,198 bytes in 2,047 blocks
==20875== total heap usage: 3,019 allocs, 972 frees, 4,496,090 bytes allocated
==20875==
==20875== LEAK SUMMARY:
==20875== definitely lost: 328 bytes in 2 blocks
==20875== indirectly lost: 0 bytes in 0 blocks
==20875== possibly lost: 1,600 bytes in 5 blocks
==20875== still reachable: 1,057,270 bytes in 2,040 blocks
==20875== suppressed: 0 bytes in 0 blocks
==20875== Rerun with --leak-check=full to see details of leaked memory
==20875==
==20875== For counts of detected and suppressed errors, rerun with: -v
==20875== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

If you look at the error summary, One output says there are errors and other says there are no errors (eventually both have leaks)

My question is - - what is counted as error in valgrind? (valgrind manual didn't helped me)

like image 281
Meluha Avatar asked Jul 01 '13 06:07

Meluha


People also ask

How can I see Valgrind errors?

Look for function names and line numbers If you compile your program with the -g flag, Valgrind will show you the function names and line numbers where errors occur.

What does Valgrind return?

By default Valgrind's malloc, realloc, etc, return a block whose starting address is 8-byte aligned or 16-byte aligned (the value depends on the platform and matches the platform default).

What is possibly lost in Valgrind?

possibly lost: heap-allocated memory that was never freed to which valgrind cannot be sure whether there is a pointer or not. still reachable: heap-allocated memory that was never freed to which the program still has a pointer at exit (typically this means a global variable points to it).

Can Valgrind be wrong?

Yes, there are false positives with Valgrind, that's why it has suppression files for particular glibc and gcc versions, for example. The false positives may arise if you are using older valgrind with newer gcc and glibc, i.e., valgrind 3.3 with glibc 2.9.


1 Answers

Memory leaks are not considered errors, they don't effect the logic of the program.

Errors are things such as invalid reads and writes.

Updated as result of comment: The invalid reads and writes in test 1 are for 5 different areas of memory which are accessed 98307 times.

Looking at the leaks, the large indirect losses in test 1 may indicated a linked data structure where only the root has been deleted.

The leaks in test 2 aren't too bad. As valgrind suggests rerun with --leak-check=full which should indicate which bit of code is causing the problem.

A full explanation of the errors can be found here

like image 66
parkydr Avatar answered Oct 07 '22 22:10

parkydr