使用/clr选项和_beginthread进行编译时,请处理泄漏. [英] Handle Leak when Compiling with /clr Option, and _beginthread.

查看:87
本文介绍了使用/clr选项和_beginthread进行编译时,请处理泄漏.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

希望您能帮助我.在过去的几天里,我一直在努力寻找产品中的手柄泄漏,但现在我怀疑我的代码之外发生了什么.似乎我的应用程序每次都调用_beginthread, 有5个泄漏的手柄.这恰好是我们的服务器应用程序,该应用程序接收许多请求并调用_beginthread,因此经过一段时间后,这变得很丑.

Hoping you can help me out. I've been trying to track down a handle leak in our product for the last few days, and I've gotten to the point where I suspect something is happening outside of our code. It seems that evertime my application calls _beginthread, there is 5 handles that leak. This happens to be our Server application, which receives many requests and calls to _beginthread, so after a period of time, this gets ugly.

此应用程序已使用/clr编译,以使用在.DLL中编写的代码进行LDAP身份验证.但是,无论是否运行任何C#/DLL代码,我们仍然在泄漏.除了对_beginthread的调用外,我已注释掉所有内容.内螺纹 proc,我所要做的就是调用_endthread ...  而且问题仍然存在-每个呼叫有5个句柄.使用Process Explorer和WinDbg工具对此进行了验证.

This application is compiled with /clr to use code written in a .DLL for LDAP Authentication.  But regardless of whether nor not any C#/DLL code gets ran, we're still leaking. I commented EVERYTHING out, except a call to _beginthread. Inside the thread proc, all I do is call _endthread...   And the problem still occurs - 5 handles on every call..  This is verified using Process Explorer and the WinDbg tool.

如果我关闭/clr标志,问题就消失了……

If I turn off the /clr flag, and the problem goes away... 

我在WinDbg中做了一个!htrace,这就是向我展示的内容.

I did a !htrace in WinDbg, and this is what its showing me..

自上次快照以来未打开的句柄:
--------------------------------------
手柄= 0x00000240-OPEN
线程ID = 0x00003754,进程ID = 0x000038a4

0x77cb4210:ntdll!ZwCreateEvent + 0x0000000c
0x7796b857:KERNEL32!Cre​​ateEventExW + 0x0000006e
0x7796b8a6:KERNEL32!Cre​​ateEventW + 0x00000027
0x72b86fdf:mscorwks!CLREvent :: CreateManualEvent + 0x00000027
0x72b21575:mscorwks!Thread :: AllocHandles + 0x0000009b
0x72b235e2:mscorwks!Thread :: InitThread + 0x000001a4
0x72b21f21:mscorwks!SetupThread + 0x000002b2
0x72bf9aac:mscorwks!IJWNOADThunk :: FindThunkTarget + 0x00000019
0x72bf9f39:mscorwks!IJWNOADThunkJumpTargetHelper + 0x0000000b
0x72a21ae1:mscorwks!IJWNOADThunkJumpTarget + 0x00000048
0x0f59dbd3:MSVCR90D!_beginthread + 0x00000233
0x0f59db6e:MSVCR90D!_beginthread + 0x000001ce
0x7796d309:KERNEL32!BaseThreadInitThunk + 0x0000000e
--------------------------------------
手柄= 0x0000023c-打开
线程ID = 0x00003754,进程ID = 0x000038a4

0x77cb4210:ntdll!ZwCreateEvent + 0x0000000c
0x7796b857:KERNEL32!Cre​​ateEventExW + 0x0000006e
0x7796b8a6:KERNEL32!Cre​​ateEventW + 0x00000027
0x72b86fdf:mscorwks!CLREvent :: CreateManualEvent + 0x00000027
0x72b21569:mscorwks!Thread :: AllocHandles + 0x0000008f
0x72b235e2:mscorwks!Thread :: InitThread + 0x000001a4
0x72b21f21:mscorwks!SetupThread + 0x000002b2
0x72bf9aac:mscorwks!IJWNOADThunk :: FindThunkTarget + 0x00000019
0x72bf9f39:mscorwks!IJWNOADThunkJumpTargetHelper + 0x0000000b
0x72a21ae1:mscorwks!IJWNOADThunkJumpTarget + 0x00000048
0x0f59dbd3:MSVCR90D!_beginthread + 0x00000233
0x0f59db6e:MSVCR90D!_beginthread + 0x000001ce
0x7796d309:KERNEL32!BaseThreadInitThunk + 0x0000000e
--------------------------------------
手柄= 0x00000238-OPEN
线程ID = 0x00003754,进程ID = 0x000038a4

0x77cb4210:ntdll!ZwCreateEvent + 0x0000000c
0x7796b857:KERNEL32!Cre​​ateEventExW + 0x0000006e
0x7796b8a6:KERNEL32!Cre​​ateEventW + 0x00000027
0x72b86fdf:mscorwks!CLREvent :: CreateManualEvent + 0x00000027
0x72b2155d:mscorwks!Thread :: AllocHandles + 0x00000083
0x72b235e2:mscorwks!Thread :: InitThread + 0x000001a4
0x72b21f21:mscorwks!SetupThread + 0x000002b2
0x72bf9aac:mscorwks!IJWNOADThunk :: FindThunkTarget + 0x00000019
0x72bf9f39:mscorwks!IJWNOADThunkJumpTargetHelper + 0x0000000b
0x72a21ae1:mscorwks!IJWNOADThunkJumpTarget + 0x00000048
0x0f59dbd3:MSVCR90D!_beginthread + 0x00000233
0x0f59db6e:MSVCR90D!_beginthread + 0x000001ce
0x7796d309:KERNEL32!BaseThreadInitThunk + 0x0000000e
--------------------------------------
手柄= 0x00000234-OPEN
线程ID = 0x00003754,进程ID = 0x000038a4

0x77cb4210:ntdll!ZwCreateEvent + 0x0000000c
0x7796b857:KERNEL32!Cre​​ateEventExW + 0x0000006e
0x7796b8a6:KERNEL32!Cre​​ateEventW + 0x00000027
0x72b86fdf:mscorwks!CLREvent :: CreateManualEvent + 0x00000027
0x72b21551:mscorwks!Thread :: AllocHandles + 0x00000077
0x72b235e2:mscorwks!Thread :: InitThread + 0x000001a4
0x72b21f21:mscorwks!SetupThread + 0x000002b2
0x72bf9aac:mscorwks!IJWNOADThunk :: FindThunkTarget + 0x00000019
0x72bf9f39:mscorwks!IJWNOADThunkJumpTargetHelper + 0x0000000b
0x72a21ae1:mscorwks!IJWNOADThunkJumpTarget + 0x00000048
0x0f59dbd3:MSVCR90D!_beginthread + 0x00000233
0x0f59db6e:MSVCR90D!_beginthread + 0x000001ce
0x7796d309:KERNEL32!BaseThreadInitThunk + 0x0000000e
--------------------------------------
手柄= 0x0000022c-打开
线程ID = 0x00003754,进程ID = 0x000038a4

0x77cb4680:ntdll!ZwDuplicateObject + 0x0000000c
0x77963d92:KERNEL32!DuplicateHandle + 0x0000012b
0x72b2365f:mscorwks!Thread :: InitThread + 0x00000174
0x72b21f21:mscorwks!SetupThread + 0x000002b2
0x72bf9aac:mscorwks!IJWNOADThunk :: FindThunkTarget + 0x00000019
0x72bf9f39:mscorwks!IJWNOADThunkJumpTargetHelper + 0x0000000b
0x72a21ae1:mscorwks!IJWNOADThunkJumpTarget + 0x00000048
0x0f59dbd3:MSVCR90D!_beginthread + 0x00000233
0x0f59db6e:MSVCR90D!_beginthread + 0x000001ce
0x7796d309:KERNEL32!BaseThreadInitThunk + 0x0000000e
0x77c916c3:ntdll!__ RtlUserThreadStart + 0x00000023
0x77c91696:ntdll!_RtlUserThreadStart + 0x0000001b
--------------------------------------

Outstanding handles opened since the previous snapshot:
--------------------------------------
Handle = 0x00000240 - OPEN
Thread ID = 0x00003754, Process ID = 0x000038a4

0x77cb4210: ntdll!ZwCreateEvent+0x0000000c
0x7796b857: KERNEL32!CreateEventExW+0x0000006e
0x7796b8a6: KERNEL32!CreateEventW+0x00000027
0x72b86fdf: mscorwks!CLREvent::CreateManualEvent+0x00000027
0x72b21575: mscorwks!Thread::AllocHandles+0x0000009b
0x72b235e2: mscorwks!Thread::InitThread+0x000001a4
0x72b21f21: mscorwks!SetupThread+0x000002b2
0x72bf9aac: mscorwks!IJWNOADThunk::FindThunkTarget+0x00000019
0x72bf9f39: mscorwks!IJWNOADThunkJumpTargetHelper+0x0000000b
0x72a21ae1: mscorwks!IJWNOADThunkJumpTarget+0x00000048
0x0f59dbd3: MSVCR90D!_beginthread+0x00000233
0x0f59db6e: MSVCR90D!_beginthread+0x000001ce
0x7796d309: KERNEL32!BaseThreadInitThunk+0x0000000e
--------------------------------------
Handle = 0x0000023c - OPEN
Thread ID = 0x00003754, Process ID = 0x000038a4

0x77cb4210: ntdll!ZwCreateEvent+0x0000000c
0x7796b857: KERNEL32!CreateEventExW+0x0000006e
0x7796b8a6: KERNEL32!CreateEventW+0x00000027
0x72b86fdf: mscorwks!CLREvent::CreateManualEvent+0x00000027
0x72b21569: mscorwks!Thread::AllocHandles+0x0000008f
0x72b235e2: mscorwks!Thread::InitThread+0x000001a4
0x72b21f21: mscorwks!SetupThread+0x000002b2
0x72bf9aac: mscorwks!IJWNOADThunk::FindThunkTarget+0x00000019
0x72bf9f39: mscorwks!IJWNOADThunkJumpTargetHelper+0x0000000b
0x72a21ae1: mscorwks!IJWNOADThunkJumpTarget+0x00000048
0x0f59dbd3: MSVCR90D!_beginthread+0x00000233
0x0f59db6e: MSVCR90D!_beginthread+0x000001ce
0x7796d309: KERNEL32!BaseThreadInitThunk+0x0000000e
--------------------------------------
Handle = 0x00000238 - OPEN
Thread ID = 0x00003754, Process ID = 0x000038a4

0x77cb4210: ntdll!ZwCreateEvent+0x0000000c
0x7796b857: KERNEL32!CreateEventExW+0x0000006e
0x7796b8a6: KERNEL32!CreateEventW+0x00000027
0x72b86fdf: mscorwks!CLREvent::CreateManualEvent+0x00000027
0x72b2155d: mscorwks!Thread::AllocHandles+0x00000083
0x72b235e2: mscorwks!Thread::InitThread+0x000001a4
0x72b21f21: mscorwks!SetupThread+0x000002b2
0x72bf9aac: mscorwks!IJWNOADThunk::FindThunkTarget+0x00000019
0x72bf9f39: mscorwks!IJWNOADThunkJumpTargetHelper+0x0000000b
0x72a21ae1: mscorwks!IJWNOADThunkJumpTarget+0x00000048
0x0f59dbd3: MSVCR90D!_beginthread+0x00000233
0x0f59db6e: MSVCR90D!_beginthread+0x000001ce
0x7796d309: KERNEL32!BaseThreadInitThunk+0x0000000e
--------------------------------------
Handle = 0x00000234 - OPEN
Thread ID = 0x00003754, Process ID = 0x000038a4

0x77cb4210: ntdll!ZwCreateEvent+0x0000000c
0x7796b857: KERNEL32!CreateEventExW+0x0000006e
0x7796b8a6: KERNEL32!CreateEventW+0x00000027
0x72b86fdf: mscorwks!CLREvent::CreateManualEvent+0x00000027
0x72b21551: mscorwks!Thread::AllocHandles+0x00000077
0x72b235e2: mscorwks!Thread::InitThread+0x000001a4
0x72b21f21: mscorwks!SetupThread+0x000002b2
0x72bf9aac: mscorwks!IJWNOADThunk::FindThunkTarget+0x00000019
0x72bf9f39: mscorwks!IJWNOADThunkJumpTargetHelper+0x0000000b
0x72a21ae1: mscorwks!IJWNOADThunkJumpTarget+0x00000048
0x0f59dbd3: MSVCR90D!_beginthread+0x00000233
0x0f59db6e: MSVCR90D!_beginthread+0x000001ce
0x7796d309: KERNEL32!BaseThreadInitThunk+0x0000000e
--------------------------------------
Handle = 0x0000022c - OPEN
Thread ID = 0x00003754, Process ID = 0x000038a4

0x77cb4680: ntdll!ZwDuplicateObject+0x0000000c
0x77963d92: KERNEL32!DuplicateHandle+0x0000012b
0x72b2365f: mscorwks!Thread::InitThread+0x00000174
0x72b21f21: mscorwks!SetupThread+0x000002b2
0x72bf9aac: mscorwks!IJWNOADThunk::FindThunkTarget+0x00000019
0x72bf9f39: mscorwks!IJWNOADThunkJumpTargetHelper+0x0000000b
0x72a21ae1: mscorwks!IJWNOADThunkJumpTarget+0x00000048
0x0f59dbd3: MSVCR90D!_beginthread+0x00000233
0x0f59db6e: MSVCR90D!_beginthread+0x000001ce
0x7796d309: KERNEL32!BaseThreadInitThunk+0x0000000e
0x77c916c3: ntdll!__RtlUserThreadStart+0x00000023
0x77c91696: ntdll!_RtlUserThreadStart+0x0000001b
--------------------------------------


我已经尽力了-您以前看过吗?您对进一步调试问题有何建议?我正在使用VS.2008.我不相信您可以在C ++项目中指定.NET版本(认为可能是在更高版本中已修复) .. 


I've exhausted everything I can - have you seen this before? What do you recommend in further debugging the problem? I'm using VS.2008.  I don't believe you can specify in the C++ Project the .NET version (thought perhaps it was fixed in a later version) .. 

 

非常感谢您提供的任何帮助和建议.

Any help and or suggestions you may have would be greatly appreciated, thanks.

迈克

 

推荐答案

你好

您应该使用__beginthreadex.

you should use __beginthreadex.

听起来更好.

 

问候

克里斯托弗·皮哈德(Christophe PICHAUD)

Christophe PICHAUD

MCSD,MCSD.NET,MCTS NET 2.0

www.christophep.com

 


这篇关于使用/clr选项和_beginthread进行编译时,请处理泄漏.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆