I am wondering if it is possible to use WinDbg to kwown the callstack that lead to the allocation of a handle.
For example:
#include <windows.h>
#include <conio.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Press ENTER to leak handles." << endl;
_getch();
cout << "Leaking handles" << endl;
for (int i = 0; i < 100; ++i)
{
HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
if (h != NULL)
{
cout << ".";
}
}
cout << "Handles leaked. Press ENTER to exit." << endl;
_getch();
return 0;
}
After building this sample and firing it up in WinDbg is it possible to get the callstack that allocated the handles, in the sample above the line:
HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
I am poking around with the !handle
command but no progress so far.
This is pertinent to handle leak analysis. I am aware of !htrace -enable
and !htrace -diff
but this is a different usage scenario (unless there is some way to combine or other usage vector for it, please provide information).