1. Install
http://www.cprogramming.com/debugging/valgrind.html
Download from http://www.valgrind.org/downloads/valgrind-3.8.1.tar.bz2
Then
Then need to install the glibc-debuginfo$ bzip2 -d valgrind-XYZ.tar.bz2 $ tar -xf valgrind-XYZ.tar$ ./configure $ make $ make install
$ sudo apt-get install valgrind
2. Write a C++ program
http://jblevins.org/log/valgrind
#include <stdlib.h>
void f(void)
{
int* x = (int*)malloc(10 * sizeof(int));
x[10] = 0; // problem 1: heap block overrun
} // problem 2: memory leak -- x not freed
int main(void)
{
f();
return 0;
}
3. Compile it with -g debug flag on
4. run
$ valgrind ./a.out