To check the memory leak we can use Valgrind tool
For linux users
go to root and
apt-get install valgrind
and check memory leak using command
**valgrind --leak-check='yes' "./executable file name" **
For example
#include <stdlib.h>
int main()
{
char *x = malloc(100); /* or, in C++, "char *x = new char[100] */
return 0;
}
EXECUTE:
% valgrind --tool=memcheck --leak-check=yes example1
This will result in some information about the program showing up, culminating in a list of calls to malloc that did not have subsequent calls to free:
==2116== 100 bytes in 1 blocks are definitely lost in loss record 1 of 1
==2116== at 0x1B900DD0: malloc (vg_replace_malloc.c:131)
==2116== by 0x804840F: main (in /home/cprogram/example1)