!htrace 显示没有调用堆栈
当我在 WinDbg 中使用 !htrace -diff 来调试句柄泄漏时,我得到很多不显示调用堆栈的句柄(可能是泄漏的句柄):
这可能是什么原因以及我必须采取哪些选项来进一步调试?
Handle = 0x000273e4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273e0 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273dc - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273d8 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273d4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273d0 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273cc - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273c8 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273c4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273c0 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273bc - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273b8 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273b4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273b0 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273ac - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273a8 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273a4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
更新:句柄泄漏似乎取决于图形驱动程序或图形卡。当我使用任何形式的 WPF 时,它就会开始泄漏,它只在某些具有特定显卡/驱动程序的 Windows XP 系统上泄漏。
When I use !htrace -diff in WinDbg to debug a handle leak, I get a lot of handles (probably the ones that are leaking) that do not show a callstack:
What could be a reason for this and what options do I have to debug this further?
Handle = 0x000273e4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273e0 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273dc - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273d8 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273d4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273d0 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273cc - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273c8 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273c4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273c0 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273bc - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273b8 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273b4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273b0 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273ac - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273a8 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Handle = 0x000273a4 - OPEN
Thread ID = 0x00001190, Process ID = 0x0000114c
--------------------------------------
Update: The handle leak seems to be depending on graphic drivers or graphic cards. It starts to leak when I use any form of WPF it only leaks on some Windows XP systems with a certain graphic cards/drivers.
调用由 ZwOpenProcess 例程 (http://msdn.microsoft.com/en-us/library/windows/hardware/ff567022(v=vs.85).aspx) 在内核模式下执行,并且后面不进行 ZwClose 调用。然后手柄就漏水了。您看不到调用堆栈,因为它们仅在从用户模式(OpenProcess / CloseHandle)执行调用时可用。
在 XP SP3 上,似乎很难找到罪魁祸首。解决方案是使用操作系统中内置的“对象引用跟踪”功能,但这条路径充满了问题(请参阅http://www.osronline.com/showthread.cfm?link=198302 以获取更多参考)。由于您发现仅当存在特定显卡时才会出现此问题,因此您可以尝试联系供应商或检查是否有更新版本的驱动程序。
Calls are performed in kernel mode by ZwOpenProcess routine (http://msdn.microsoft.com/en-us/library/windows/hardware/ff567022(v=vs.85).aspx) and not followed by a ZwClose call. Then the handle leaks. You don't see the callstacks because they are only available when calls are performed from user mode (OpenProcess / CloseHandle).
On an XP SP3, it seems difficult to find the culprit. The solution would be to use the 'Object reference tracing' functionality built in the OS, but this path is paved with issues (see http://www.osronline.com/showthread.cfm?link=198302 for further references). Since you found out this issue arises only when a particular video card is present, you can try to contact the vendor or check for a newer version of the driver.