Valgrind Frequently Asked Questions
Second, if your program is statically linked, most Valgrind tools won’t work as well, because they won’t be
able to replace certain functions, such as
malloc
, with their own versions.
A key indicator of this is if
Memcheck says:
All heap blocks were freed -- no leaks are possible
when you know your program calls
malloc
. The workaround is to avoid statically linking your program.
4.6.
Why doesn’t Memcheck find the array overruns in this program?
int static[5];
int main(void)
{
int stack[5];
static[5] = 0;
stack [5] = 0;
return 0;
}
Unfortunately, Memcheck doesn’t do bounds checking on global or stack arrays. We’d like to, but it’s just not
possible to do in a reasonable way that fits with how Memcheck works. Sorry.
However, the experimental tool SGcheck can detect errors like this.
Run Valgrind with the
--tool=exp-sgcheck
option to try it, but be aware that it is not as robust as Memcheck.
5. Miscellaneous
5.1.
I tried writing a suppression but it didn’t work. Can you write my suppression for me?
Yes!
Use the
--gen-suppressions=yes
feature to spit out suppressions automatically for you.
You
can then edit them if you like, eg.
combining similar automatically generated suppressions using wildcards
like
’*’
.
If you really want to write suppressions by hand, read the manual carefully.
Note particularly that C++
function names must be mangled (that is, not demangled).
5.2.
With Memcheck’s memory leak detector, what’s the difference between "definitely lost", "indirectly lost",
"possibly lost", "still reachable", and "suppressed"?
The details are in the Memcheck section of the user manual.
In short:
• "definitely lost" means your program is leaking memory -- fix those leaks!
7