Understanding handle leaks and how to use !htrace to find them
- Posted: Sep 14, 2007 at 11:35 AM
- 25,979 Views
- 8 Comments
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
Right click “Save as…”
- Mid Quality WMV (Lo-band, Mobile)
Hello, my name is Jeff Dailey, I’m an Escalation Engineer for the Global Escalation Services Platforms team. I’d like to show you how to debug and find leaking handles within your application or other process. We can do this with the !htrace command in windbg . Windbg is the Microsoft Windows Debugger most of us use in GES/CPR for debugging.
Handles are a value we use in user mode, that when passed to a call that transitions to kernel, are used as an offset in your handle table to reference kernel mode objects. Kernel mode objects are generally allocated from pool. If you are having pool consumption problems and seeing errors like 2020 or 2019’s reported there is a good chance you may have a handle leak associated with them. This is generally due to not doing a CloseHandle() on the handle when you have finished using it.
The following is the sample source for a handle leak that we will be debugging in our demo video.
// leakyhandles.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
void fun1(void);
void fun2(void);
void fun3(void);
void fun4(void);
int main(int argc, char* argv[])
{
while(1)
{
fun1();
fun2();
Sleep(100);
}
return 0;
}
void fun1(void)
{
fun3();
}
void fun2(void)
{
fun4();
}
void fun3(void)
{
HANDLE hEvent;
hEvent = CreateEvent(NULL,TRUE,TRUE,NULL);
CloseHandle(hEvent);
}
void fun4(void)
{
HANDLE hEvent2;
hEvent2 = CreateEvent(NULL,TRUE,TRUE,NULL);
}
Thank you.
Jeff Dailey
Escalation Engineer (Platforms core team)
Comments Closed
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Seems like the CHM which you have shown comes with MS confidential (private) version of windbg...
(though there is not much difference in the page thats shown!)
But thanks for taking initiative and start giving nice small tutorials on debugging with windbg..
Hope to see more of those trainings in future...
Cheers,
Volker
http://www.voneinem-windbg.blogspot.com/
i have tried for several times to watch this video, but every time after it played about 1 or 2 mins, it just stopped...
i have no way to finish watching the video, is there anyway i can do about it?? my bandwidth is 12mb download/1mb upload, so it's not a bandwidth problem.
is there anyway i can download the video or just think a way to help me be able to watch it....
Going to play with this method on my machine now...
thanks for the tutorial..
I am alos not able to watch the video ....which tool helped to donwload wmv...?
You can click on the "Formats:" drop-down and in the list, right-click the WMV and choose "Save-As". At least that worked for me. This was the direct link from that:
http://mschnlnine.vo.llnwd.net/d1/ch9/1/2/6/7/5/2/341851_leakyhandles.wmv
Hi, that video was very helpful, thanks for that Jeff. And thanks to c0decafe for the download link.
Remove this comment
Remove this thread
close