Using Valgrind

Valgrind is a powerful toolset that can help to debug programs especially for memory-related issues.

A few references:

Frequently Used Commands

  • Install the tool
# valgrind
$ sudo apt-get install valgrind
# useful tools that can be used together with valgrind
$ sudo apt-get install kcachegrind graphviz
  • Memory error check
# quick check
$ valgrind <name-of-executable>
# full memory leak check
$ valgrind --leak-check=full <name-of-executable>
  • Program profiling
# profile program and get an output file like callgrind.out.xxxxxx
$ valgrind --tool=callgrind <name-of-executable>
# then you can load the file with Kcachegrind
$ kcachegrind <name-of-profiling-output-file>