finding memory leaks with umdh

11

Upload: zachary-d-blair

Post on 20-May-2015

5.310 views

Category:

Technology


8 download

DESCRIPTION

A brief introduction to UMDH, a tool for finding memory leaks in Windows applications.

TRANSCRIPT

Page 1: Finding Memory Leaks with UMDH
Page 2: Finding Memory Leaks with UMDH

Stands for User Mode Dump Heap

Can be downloaded for free as part of the Windows 7 SDK (also works for Windows XP)

Helps you to find memory leaks in running processes!

Page 3: Finding Memory Leaks with UMDH

1. Set the _NT_SYMBOL_PATH environment var to:

2. Append the path to your executable

srv*c:\symbols*http://msdl.microsoft.com/download/symbols;

Page 4: Finding Memory Leaks with UMDH

1. Flag your process under test as being monitored:

2. Start your process under test:

3. Take an initial “snapshot” of allocated memory as Test.exe runs:

C:> gflags -i Test.exe +ust

C:> umdh -pn:Test.exe -f:C:\f1.txt

C:> Test.exe

Page 5: Finding Memory Leaks with UMDH

4. Exercise your program in a way that you think may make it leak memory.

5. Take a second snapshot and save it with a different file name from the first.

6. Use UMDH to “diff” the first and last snapshots taken to get the best idea of what has leaked

C:> umdh -d f1.txt f2.txt > f12.txt

C:> umdh -pn:Test.exe -f:C:\f2.txt

Page 6: Finding Memory Leaks with UMDH

The “diff” file shows a stack trace, and the

number/size of allocations that were allocated but not freed between two snapshots.

+ 483328 ( 487424 - 4096) 119 allocs BackTrace23FF

+ 118 ( 119 - 1) BackTrace23FF allocations

ntdll!RtlDebugAllocateHeap+000000E1

ntdll!RtlAllocateHeapSlowly+00000044

ntdll!RtlAllocateHeap+00000E64

kernel32!FindNextFileW+00000077

kernel32!FindNextFileA+00000028

MSVCR80D!findnext64i32+00000178

Test!readdir+00000075 (c:\myproject\util.cpp, 674)

Page 7: Finding Memory Leaks with UMDH

+ 483328 ( 487424 - 4096) 119 allocs BackTrace23FF

+ 118 ( 119 - 1) BackTrace23FF allocations

ntdll!RtlDebugAllocateHeap+000000E1

ntdll!RtlAllocateHeapSlowly+00000044

ntdll!RtlAllocateHeap+00000E64

kernel32!FindNextFileW+00000077

kernel32!FindNextFileA+00000028

MSVCR80D!findnext64i32+00000178

Test!readdir+00000075 (c:\myproject\util.cpp, 674)

Bytes “leaked” between the two snapshots

Stacktrace showing where the “leaked”

memory was allocated.

Page 8: Finding Memory Leaks with UMDH

At the very bottom of the file, there is an overall summary of how much memory was allocated but not freed. E.g.:

If used as part of an automated test, it is fairly easy to extract the “Total increase” number using a Perl script and graphs of memory allocations and usage over time.

Total increase == 13919896 requested + 830364 overhead = 14750260

Page 9: Finding Memory Leaks with UMDH

UMDH is a useful tool for finding memory leaks in Windows applications.

Its output is a file listing outstanding memory allocations that can be read directly, or processed by another program or script.

Page 11: Finding Memory Leaks with UMDH