Handle Leak when Compiling with /clr Option, and _beginthread.
-
Hi all, 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 everytime 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. 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. If I turn off the /clr flag, and the problem goes away... I did a !htrace in WinDbg, and this is what its showing me.. 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!_be