views:

158

answers:

1

I'm finding leaked heap blocks by using the following command in WinDbg

!heap –l

With each leaked heap block I get, I'm running to following to get the stack trace.

!heap -p -a leakedheapblock

The following is the result of this command:

address 1c841cc0 found in
_HEAP @ 3930000
  HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
    1c851cc0 0009 0000  [03]   1c851ce8    0000c - (busy)
    Trace: 84f8
    7c873c19 ntdll!RtlpDphNormalHeapAllocate+0x00000030
    7c876870 ntdll!RtlpDebugPageHeapAllocate+0x00000335
    7c8794a8 ntdll!RtlDebugAllocateHeap+0x0000002d
    7c8531e4 ntdll!RtlAllocateHeapSlowly+0x00000041
    7c83d97a ntdll!RtlAllocateHeap+0x00000e9f
    1699d238 MyLibrary!malloc+0x0000007a

How can I find the piece of code in 'MyLibrary' that leaks.

A: 

There is a nice guide about this in MSDN: Memory Leak Detection Enabling