Memory Leak Check Using Valgrind

If you are a Developer / QA engineer, you may need to check for memory leaks before field use of your product. Though there are some licensed tools for memory leak, however you can make use of valgrind if you are using unix/linux as development environment. The commands explained below are being used in Ubuntu 12.04 LTS systems.

Pre-requisites
  1. Install libc6 package as described in below step.
  2. If your machine is 64 bit, and you want to use valgrind for 32 bit executables use below command.
    apt-get install libc6-dbg:i386

    or
    If your machine is 64 bit, and you want to use valgrind for 64 bit executables use below command.

    apt-get install libc6-dbg
  3. To check memory leak start executable with below command
    valgrind --tool=memcheck --leak-check=yes --log-file=/log/file/path/filename ./your-executable
  4. Use --track-origins=yes option to find the origins of undefined values
Installing latest valgrind (3.10.1)

If you want to install latest valgrind, download the source code from here.
Then follow follow below step to compile and install it. For more options please check readme / install files.

sed -i 's/-mt//g' configure
sed -i 's|/doc/valgrind||' docs/Makefile.in
./configure --prefix=/usr --datadir=/usr/share/doc/valgrind-3.10.1
make
make install