Advanced Windows Debugging got me hooked onto Detours and that led me to experiment with it a bit more. It resulted in this. Over the past three days, I have been working on using Detours to build a memory leak detection tool. MemAnalysis is finally done (v1, that is) and can track memory allocation and release when done using the following APIs:
- VirtualAlloc
- VirtualFree
- HeapAlloc
- HeapFree
- HeapDestroy
Once the application being analyzed exits, MemAnalysis produces a report with details on how many allocations took place, how many of them were freed and how much memory was not released. Below is a sample output:
Total Allocations: 8605
Total Virtual allocations: 1
Freed Virtual allocations: 1
Virtual allocation leaked size: 0 bytes
Total Heap allocations: 8604
Freed Heap allocations: 4189
Heap allocation leaked size: 1965244 bytes
==============================================
2344 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 0019CDD0h
548 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 0019D700h
16 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 0019C718h
308 bytes were leaked; Allocation method: Heap; Handle: 10000h; Address: 00010588h
60 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 0019C4F0h
24 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 00184830h
1826 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 0019D700h
2032 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 0019DE30h
538 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 0019D700h
104 bytes were leaked; Allocation method: Heap; Handle: 180000h; Address: 0019A600h
It is a free download and can be downloaded from here.
Note: If not already present on your machine, you need to have VC++ 2008 runtimes installed. The X86 version can be downloaded from here and the X64 version is here.