I'm trying to learn how to troubleshoot memory leaks with umdh.exe. In order to do it I wrote a sample app:
void MemoryLeakTest(int argc, _TCHAR* argv[]);
int _tmain(int argc, _TCHAR* argv[])
{
MemoryLeakTest(argc, argv);
return 0;
}
void MemoryLeakTest(int argc, _TCHAR* argv[])
{
if (argc != 3)
{
wcout << "HelloWorld.exe <number of allocations> <number of bytes>" << endl;
getchar();
return;
}
int numAllocations = _wtoi(argv[1]);
int numBytes = _wtoi(argv[2]);
wcout << "Num allocations: " << numAllocations << ", num bytes: " << numBytes << endl;
wcout << "Press any key to start..." << endl;
getchar();
for (int i = 0; i < numAllocations; ++i)
{
void* unusedMemory = new byte[numBytes];
if ((i % (numAllocations / 100)) == 0)
{
wcout << i << endl;
Sleep(100);
}
}
wcout << "Press any key to finish..." << endl;
getchar();
}
Compiled (release), configured umdh.exe:
- set _NT_SYMBOL_PATH=http://msdl.microsoft.com/symbols/download;C:\TestProjects\HelloWorld\x64\Release;
- gflags.exe /i HelloWorld.exe +ust
Then did the experiment:
- HelloWorld.exe 10000 1000
- Waited till it stops @ first getchar
- umdh.exe -pn:helloworld.exe -f:c:\first.log
- Continued execution, waited till it stops @ second getchar
- umdh.exe -pn:helloworld.exe -f:c:\second.log
What I noticed is that no matter with which parameters I call, whether it is 100 allocations or 1000 allocations, first.log and second.log look very similar (for different experiments).
- umdh.exe -d c:\first.log c:\second.log -f:c:\result.log
And then I get the only stack with only 17 allocs (instead of expected 1000):
+ 17000 ( 17000 - 0) 17 allocs BackTraceB5023D4D
+ 17 ( 17 - 0) BackTraceB5023D4D allocations
ntdll!memset+165B9
MSVCR120!malloc+5B
MSVCR120!operator new+1F
HelloWorld!MemoryLeakTest+108 (c:\my\main\private\testproject\debugit\helloworld\helloworld.cpp, 40)
HelloWorld!wmain+9 (c:\my\main\private\testproject\debugit\helloworld\helloworld.cpp, 16)
HelloWorld!__tmainCRTStartup+10F (f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c, 623)
KERNEL32!BaseThreadInitThunk+D
ntdll!RtlUserThreadStart+1D
UPDATED: TaskProcess shows that both private bytes and commit size grow on expected value.
UPDATED2: DebugDiag shows a leak correctly with 10000 allocations and a few sampled call stacks pointing to right location.
Any idea what I'm doing wrong?
Thank you!