Skip to content

[Programming] Check C and CPP memory leak with Valgrind on Ubuntu

lifuzu edited this page Oct 1, 2013 · 1 revision
  1. Install Valgrind:

sudo apt-get install valgrind
  1. Run the command to detect:

valgrind --leak-check=full --show-reachable=yes ./program arg1 arg2 ...

For example:


valgrind --leak-check=full --show-reachable=yes ./nook_hsm_process -s sbk.key.enc -w wv_plain.key.enc -a AESKEY_1 -r RSAKEY_1 -d /dev/cs2 -u hsmuser -p PASSWORD -o wvkwsbk.bin
  1. Check the result:

==4798== LEAK SUMMARY:
==4798==    definitely lost: 0 bytes in 0 blocks
==4798==    indirectly lost: 0 bytes in 0 blocks
==4798==      possibly lost: 0 bytes in 0 blocks
==4798==    still reachable: 576 bytes in 2 blocks
==4798==         suppressed: 0 bytes in 0 blocks

(Definitely Lost and Possibly Lost should be fixed!)

REFERENCE:

  1. http://valgrind.org/docs/manual/manual.html

Clone this wiki locally