Tool for detecting memory leaks

c, c++, memory-leaks, memory-management, unix

Solution

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()`

Problem

How do memory leak detection tools like purify and valgrind work? How can I design and implement my own such tool?

Original source

Related problems