NAME
valgrind - a suite of tools for debugging and profiling programs
SYNOPSIS
valgrind [valgrind-options] [your-program] [your-program-options]
DESCRIPTION
Valgrind is a flexible program for debugging and profiling Linux executables. It consists of a core, which provides a synthetic CPU in software, and a series of
debugging and profiling tools. The architecture is modular, so that new tools can be created easily and without disturbing the existing structure.
Some of the options described below work with all Valgrind tools, and some only work with a few or one. The section MEMCHECK OPTIONS and those below it describe
tool-specific options.
This manual page covers only basic usage and options. For more comprehensive information, please see the HTML documentation on your system:
$INSTALL/share/doc/valgrind/html/index.html, or online: http://www.valgrind.org/docs/manual/index.html.
Example:
wgao@pek-wgao-d1:~$ cat leak.c
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
int main()
{
int * x = NULL;
/*int a[10] = {0};
x = a;
*x = 1;
printf ("%d\n",*x);
x[9] = 0;
printf ("%d\n",*x);
*/
x = malloc (10 * sizeof(int));
memset(x,0,10);
*x = 1;
printf ("%d\n",*x);
x[9] = 0;
#free(x);
}
wgao@pek-wgao-d1:~$
wgao@pek-wgao-d1:~$ gcc -o leak -O0 -g leak.c
wgao@pek-wgao-d1:~$ sudo valgrind --leak-check=full -v ./leak
==14363== HEAP SUMMARY:
==14363== in use at exit: 40 bytes in 1 blocks
==14363== total heap usage: 1 allocs, 0 frees, 40 bytes allocated
==14363==
==14363== Searching for pointers to 1 not-freed blocks
==14363== Checked 72,456 bytes
==14363==
==14363== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
==14363== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14363== by 0x40055D: main (leak.c:15)
==14363==
==14363== LEAK SUMMARY:
==14363== definitely lost: 40 bytes in 1 blocks
==14363== indirectly lost: 0 bytes in 0 blocks
==14363== possibly lost: 0 bytes in 0 blocks
==14363== still reachable: 0 bytes in 0 blocks
==14363== suppressed: 0 bytes in 0 blocks
==14363==
==14363== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
--14363--
--14363-- used_suppression: 2 dl-hack3-cond-1
==14363==
==14363== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
wgao@pek-wgao-d1:~$