valgrind – memory debugger



Valgrind is more in general memory debugger tool. 
Debuggers Specially used to figure out memory leaks in our system programming with the help of Valgrind. It's a great tool where most focussed in memory profiling. Ufh! not like gdb.

Valgrind was originally designed to be a free memory debugging tool for Linux on x86, but has since evolved to become a generic framework for creating dynamic analysis tools such as checkers and profilers.

usefull links:
https://valgrind.org


q). what is valgrind ?
*. valgrind is a open sourced tool by which we debug memory stuff.

q).How valgrind helps me?
*. When you’re done with it, you use free to return it to the OS so that
   it can be used by other programs. Failing to do this will cause your
   program to leak memory, but Valgrind will help you track these leaks
   down.

Q).How to install valgrind in our machine?
*. sudo apt-get install valgrind

q).example usage of valgrind?

*. valgrind --leak-check=full --track-origins=yes -v ./exe

=================================================================
prashad@ubuntu:~/test/memory_leak$ vi find_leak.c
prashad@ubuntu:~/test/memory_leak$ gcc find_leak.c
prashad@ubuntu:~/test/memory_leak$ valgrind ./a.out 
==2859== Memcheck, a memory error detector
==2859== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2859== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==2859== Command: ./a.out
==2859== 
==2859== 
==2859== HEAP SUMMARY:
==2859==     in use at exit: 10 bytes in 1 blocks
==2859==   total heap usage: 1 allocs, 0 frees, 10 bytes allocated
==2859== 
==2859== LEAK SUMMARY:
==2859==    definitely lost: 10 bytes in 1 blocks
==2859==    indirectly lost: 0 bytes in 0 blocks
==2859==      possibly lost: 0 bytes in 0 blocks
==2859==    still reachable: 0 bytes in 0 blocks
==2859==         suppressed: 0 bytes in 0 blocks
==2859== Rerun with --leak-check=full to see details of leaked memory
==2859== 
==2859== For counts of detected and suppressed errors, rerun with: -v
==2859== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

prashad@ubuntu:~/test/memory_leak$ cat find_leak.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int *p = malloc(10);
    //free(p);
}
=================================================================