Valgrind Frequently Asked Questions
• A leak error message involving an unloaded shared object:
84 bytes in 1 blocks are possibly lost in loss record 488 of 713
at 0x1B9036DA: operator new(unsigned) (vg_replace_malloc.c:132)
by 0x1DB63EEB: ???
by 0x1DB4B800: ???
by 0x1D65E007: ???
by 0x8049EE6: main (main.cpp:24)
4.3.
The stack traces given by Memcheck (or another tool) seem to have the wrong function name in them. What’s
happening?
Occasionally Valgrind stack traces get the wrong function names.
This is caused by glibc using aliases
to effectively give one function two names.
Most of the time Valgrind chooses a suitable name, but very
occasionally it gets it wrong. Examples we know of are printing
bcmp
instead of
memcmp
,
index
instead of
strchr
, and
rindex
instead of
strrchr
.
4.4.
My program crashes normally, but doesn’t under Valgrind, or vice versa. What’s happening?
When a program runs under Valgrind, its environment is slightly different to when it runs natively.
For
example, the memory layout is different, and the way that threads are scheduled is different.
Most of the time this doesn’t make any difference, but it can, particularly if your program is buggy.
For
example, if your program crashes because it erroneously accesses memory that is unaddressable, it’s possible
that this memory will not be unaddressable when run under Valgrind. Alternatively, if your program has data
races, these may not manifest under Valgrind.
There isn’t anything you can do to change this, it’s just the nature of the way Valgrind works that it cannot
exactly replicate a native execution environment. In the case where your program crashes due to a memory
error when run natively but not when run under Valgrind, in most cases Memcheck should identify the bad
memory operation.
4.5.
Memcheck doesn’t report any errors and I know my program has errors.
There are two possible causes of this.
First, by default, Valgrind only traces the top-level process. So if your program spawns children, they won’t
be traced by Valgrind by default. Also, if your program is started by a shell script, Perl script, or something
similar, Valgrind will trace the shell, or the Perl interpreter, or equivalent.
To trace child processes, use the
--trace-children=yes
option.
If you are tracing large trees of processes, it can be less disruptive to have the output sent over the network.
Give Valgrind the option
--log-socket=127.0.0.1:12345
(if you want logging output sent to port
12345
on
localhost
). You can use the valgrind-listener program to listen on that port:
valgrind-listener 12345
Obviously you have to start the listener process first. See the manual for more details.
6