Memcheck: a memory error detector
64 bytes in 4 blocks are still reachable in loss record 2 of 4
at 0x........: malloc (vg_replace_malloc.c:177)
by 0x........: mk (leak-cases.c:52)
by 0x........: main (leak-cases.c:74)
32 bytes in 2 blocks are indirectly lost in loss record 1 of 4
at 0x........: malloc (vg_replace_malloc.c:177)
by 0x........: mk (leak-cases.c:52)
by 0x........: main (leak-cases.c:80)
Because there are different kinds of leaks with different severities, an interesting question is this: which leaks should
be counted as true "errors" and which should not?
The answer to this question affects the numbers printed in the
ERROR SUMMARY
line, and also the effect of the
--error-exitcode
option.
Memcheck uses the following
criteria:
• First, a leak is only counted as a true "error" if
--leak-check=full
is specified. In other words, an unprinted
leak is not considered a true "error". If this were not the case, it would be possible to get a high error count but not
have any errors printed, which would be confusing.
• After that, definitely lost and possibly lost blocks are counted as true "errors".
Indirectly lost and still reachable
blocks are not counted as true "errors", even if
--show-reachable=yes
is specified and they are printed; this
is because such blocks don’t need direct fixing by the programmer.
4.3. Memcheck Command-Line Options
--leak-check=<no|summary|yes|full> [default:
summary]
When enabled, search for memory leaks when the client program finishes. If set to
summary
, it says how many leaks
occurred. If set to
full
or
yes
, it also gives details of each individual leak.
--show-possibly-lost=<yes|no> [default:
yes]
When disabled, the memory leak detector will not show "possibly lost" blocks.
--leak-resolution=<low|med|high> [default:
high]
When doing leak checking, determines how willing Memcheck is to consider different backtraces to be the same for
the purposes of merging multiple leaks into a single leak report.
When set to
low
, only the first two entries need
match. When
med
, four entries have to match. When
high
, all entries need to match.
For hardcore leak debugging,
you probably want to use
--leak-resolution=high
together with
--num-callers=40
or some such large number.
Note that the
--leak-resolution
setting does not affect Memcheck’s ability to find leaks. It only changes how
the results are presented.
--show-reachable=<yes|no> [default:
no]
When disabled, the memory leak detector only shows "definitely lost" and "possibly lost" blocks.
When enabled,
the leak detector also shows "reachable" and "indirectly lost" blocks.
(In other words, it shows all blocks, except
suppressed ones, so
--show-all
would be a better name for it.)
57