Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool for detecting memory leaks [closed]

How do memory leak detection tools like purify and valgrind work?

How can I design and implement my own such tool?

like image 251
user343826 Avatar asked May 18 '10 09:05

user343826


2 Answers

Such tools usually instrument the exeutable with their own code. for instance they replace every call to malloc() and free() with their own functions which allows them to follow every allocation.

In Visual Studio this can be done automatically using just the C Runtime Library using functions from the family of _CrtDumpMemoryLeaks()

like image 102
shoosh Avatar answered Sep 24 '22 12:09

shoosh


For basic leak detection you just need to hook into low level memory allocation routines, e.g. by patching malloc/free. You then track all allocations and subsequently report any that have not been freed at an appropriate point, e.g. just prior to exit.

like image 29
Paul R Avatar answered Sep 25 '22 12:09

Paul R