Valgrind is a software development tool for memory debugging, memory leak detection, and performance analysis.
Valgrind's original author was Julian Seward, who won the second Google-o ' Reilly Open source Code award in 2006 for his work on the development of Valgrind.
Valgrind complies with the GNU General Public License Terms and is a free software.
official website
http://www.valgrind.org
Download and install
#wget http://www.valgrind.org/downloads/
valgrind-3.8.1.tar.bz2
#tar XVF valgrind-3.8.1.tar.bz2
#cd valgrind-3.8.1
#./configure--prefix=/usr/local/webserver/valgrind
#make
#make Install
Test Code
Copy Code code as follows:
#include <stdlib.h>
int* func (void)
{
int* x = malloc (A * sizeof (int));
X[10] = 0; Problem 1: Array subscript out of bounds
}
int main (void)
{
int* X=null;
X=func ();
Free (x);
X=null;
return 0; Issue 2: Memory not released
}
compiling
#gcc-G-O test test.c
Memory Check
#valgrind--tool=memcheck--leak-check=yes--show-reachable=yes./test
Report:
description
Invalid Write of size 4:4 bytes in array out of bounds
Bytes in 1 blocks: Indicates a memory leak 40 bytes due to program exit
Fix bugs, re-check hints, no memory leaks
Document:
The Memcheck tool contained in Valgrind can check the following program errors:
Using uninitialized memory (use of uninitialised memory)
Use memory that has been freed (reading/writing memory after it has been free ' d)
Use more than malloc allocated memory space (reading/writing off the end of malloc ' d blocks)
Illegal access to stack (reading/writing inappropriate areas on the stack)
Whether the requested space is released (Memory leaks–where pointers to malloc ' d blocks are lost)
Malloc/free/new/delete application and free memory matching (mismatched use of malloc/new/new [] vs Free/delete/delete [])
Overlap between src and DST (overlapping SRC and DST pointers in memcpy () and related functions)
Repeat free