Skip to main content

Posts

Showing posts from April, 2016

How to quickly investigate memory leak in your application

Every C/C++ software developer meet problem of memory leak (allocating memory over time which is not freed). If you would like to know how to investigate memory leak problem in your application, this article is for you. For memory leak investigation I recommend to use valgrind tool. Especially with it's Massif tool. Let's see the example how we could use that tool for memory leak investigation. Below snippet of code has lots of points where memory leak can occur. 1 #include <stdio.h> 2 3 void allocmem1 () 4 { 5 char * memleak 2 = malloc ( 100 * sizeof ( char )) ; 6 } 7 8 void allocmem2 () 9 { 10 char * memleak 2 = malloc ( 10 * sizeof ( char )) ; 11 allocmem1 () ; 12 } 13 14 void allocmem3 () 15 { 16 char * memleak 2 = malloc ( 5 * sizeof ( char )) ; 17 allocmem2 () ; 18 } 19 20 int main ( int argc , const char ** argv ) 21 { 22 char * memleak 1 = malloc ( 5 * sizeof ( char )) ; 23