Table of contents
Install Valgrind via APT
sudo apt install valgrind
Compile the source program
To compile the program use the following flags:
- -g3
- -O0 (optional)
Example in C
gcc -g -Wall *.c
Example in C++
g++ -g -Wall *.cpp
Execute target with Valgrind
To execute the program once you have compiled it:
./valgrind program
Advanced options
Enable extensive leak checking
For extensive testing you could also use the following flags:
--leak-check=full
--show-leak-kinds=all
--leak-resolution=high
--track-origins=yes --vgdb=yes
Ignore forked children
To ignore forked children use the flag:
--child-silent-after-fork=yes
Multithreading
If you are creating threads you could also use one of following tools:
--tool=drd
or
--tool=helgrind
References: