Example : leak.cpp

#include<iostream>

int main()

{

int *iptr = new int;                            // 4 byte

char *chptr = new char;                    // 1 byte

double *dblptr = new double;          //  8 byte

return 0;

}

// 13 byte memory leak

$ g++ leak.cpp

1 Valgring tool (linux)

Installation : $ sudo apt-get install valgrind

user : valgrind --tool=memcheck --leak-check=yes "binary" 

binary eg a.out

output
==6042== LEAK SUMMARY:
==6042==    definitely lost: 13 bytes in 3 blocks
==6042==    indirectly lost: 0 bytes in 0 blocks
==6042==      possibly lost: 0 bytes in 0 blocks
==6042==    still reachable: 0 bytes in 0 blocks
==6042==         suppressed: 0 bytes in 0 blocks

2 DrMemory

Installation : download from link

download tar file and extract in home dir

copy the bin folder location form the folder and add to PATH env var
eg: /home/pmvanker/DrMemory-Linux-2.3.0-1/bin

$ vim ~/.bashrc
"add this line at the end "
export PATH=/home/pmvanker/DrMemory-Linux-2.3.0-1/bin:$PATH

home/pmvanker is not same for your machine

$ source ~/.bashrc

now able to run drmemory cmd
$ drmemory -- a.out

Output
~~Dr.M~~ ERRORS FOUND:
~~Dr.M~~       0 unique,     0 total unaddressable access(es)
~~Dr.M~~       0 unique,     0 total uninitialized access(es)
~~Dr.M~~       0 unique,     0 total invalid heap argument(s)
~~Dr.M~~       0 unique,     0 total warning(s)
~~Dr.M~~       3 unique,     3 total,     13 byte(s) of leak(s)
~~Dr.M~~       0 unique,     0 total,      0 byte(s) of possible leak(s)