Posts

Showing posts from October, 2009

How to locate a memory leak in C?

Though it is an extremely programming intensive task to fix a memory leak, still if possible to get any help in finding the leaking source hint, it is really very helpful, trust me. On Ubuntu you may get many memory leak fix solutions. But the best which did saved the day turned up to be   Valgrind ... tada... If you don't have valgrind installed you can install it by apt-get install valgrind Valgrind comes with a command prompt interface. Although its GUI clients are also available like Valkyrie etc, but command line interface is enough. To check memory leak location you can execute the following command definitely with all the supportive arguments valgrind --leak-check=full ./executable arg1 arg2 This will show the memory leak in the bottom up fashion showing the stack. For instance if there is a memory leak in func1(), than the stack would show something like: malloc() func1() main() You have to intutively identify the hint of the stack. For exa