First page Back Continue Last page Overview Graphics

Valgrind


Notes:

Valgrind is smart - it is by the author of bzip2 - and an ex-Manchester Uni postgrad.
It emulates your entire program (in an efficient way); but adds code to spot things that go wrong.
Compile the last example, badread: gcc badread.c -g -o badread
From the source we can see two errors; it reads a flag variable without initialising it and allocates memory and forgets about it.
Valgrind ./badread
Shows lots of errors about reads from unitialised memory from around the printf and a backtrace to show where it was called from.
Valgrind --leak-check=yes shows the unfreed malloc; and where the malloc was made from.