Hi all,

It works fine on XP Professional but not on WinNT 4.0 and Win2k.
While PrivateBytes, VirtualBytes,etc doing very fine I see Handle count keep
going
up in the Task Manger and PerfMon.
Its about handle leaks but I wonder if anything special about winnt 4.0 and
win2k. In the
NT Service I'm creating threads in a loop, threads return fine and I do
close handles using CloseHandle() in a loop. And the return value of
CloseHandle() for all the handles looks fine (as viewed using
OutputDebugString() in the debugger and WaitForMultipleObjects always is
WAIT_OBJECT_0)


for(i = 0;i<z;i++)
{
array[i] = CreateThread(0,
0, // use default stack size
(LPTHREAD_START_ROUTINE) ThreadProc, // thread function
NULL, // argument to thread function
0, // use default creation flags
&dwThreadID);
}



DWORD waitfor = WaitForMultipleObjects(noofprocess,hThread,TRUE,freq);
int relhandles = 0;

switch(waitfor)
{
char clip[512];
BOOL close;

case WAIT_TIMEOUT:
OutputDebugString(_T(" WAIT_TIMEOUT"));
for(relhandles = 0; relhandles < curIns; relhandles++)
{
if(hThread[relhandles] !=0)
{

close = CloseHandle(hThread[relhandles]);

if(close != 0)
{
sprintf(clip,_T("\n Handle %d closed \n"),relhandles);
OutputDebugString(clip);
}
else
{
sprintf(clip,_T("\n Close Handle %d failed \n"),relhandles);
OutputDebugString(clip);
_Module.LogEvent(_T(clip));
}
}
}
break;


case WAIT_ABANDONED_0:

OutputDebugString(_T("WAIT_ABANDONED"));
break;

case WAIT_OBJECT_0:
OutputDebugString(_T("WAIT_OBJECT_0"));

for(relhandles = 0; relhandles < curIns; relhandles++)
{
if(hThread[relhandles] !=0)
{

close = CloseHandle(hThread[relhandles]);

if(close != 0)
{
sprintf(clip,_T("\n Handle %d closed \n"),relhandles);
OutputDebugString(clip);
}
else
{
sprintf(clip,_T("\n Close Handle %d failed \n"),relhandles);
OutputDebugString(clip);
_Module.LogEvent(_T(clip));
}
}
}
break;
default:
OutputDebugString(_T("default"));

}



thank you,
vinod

Re: handle leaks..? by vinod

vinod
Tue Mar 02 04:22:53 CST 2004

one other interesting thing I found out....
I made the function code very simple, that has the forloop that creates
threads, containing the mentioned forloop only.....
I made my ThreadProc do nothing but just Sleep(10000) and return.....still
everything is fine but handle leaks exist on NT 4.0

thx,
vinod


"vinod kumar" <naga_vinod@yahoo.com> wrote in message
news:%23qLT1HEAEHA.3284@TK2MSFTNGP09.phx.gbl...
> Hi all,
>
> It works fine on XP Professional but not on WinNT 4.0 and Win2k.
> While PrivateBytes, VirtualBytes,etc doing very fine I see Handle count
keep
> going
> up in the Task Manger and PerfMon.
> Its about handle leaks but I wonder if anything special about winnt 4.0
and
> win2k. In the
> NT Service I'm creating threads in a loop, threads return fine and I do
> close handles using CloseHandle() in a loop. And the return value of
> CloseHandle() for all the handles looks fine (as viewed using
> OutputDebugString() in the debugger and WaitForMultipleObjects always is
> WAIT_OBJECT_0)
>
>
> for(i = 0;i<z;i++)
> {
> array[i] = CreateThread(0,
> 0, // use default stack size
> (LPTHREAD_START_ROUTINE) ThreadProc, // thread function
> NULL, // argument to thread function
> 0, // use default creation flags
> &dwThreadID);
> }
>
>
>
> DWORD waitfor = WaitForMultipleObjects(noofprocess,hThread,TRUE,freq);
> int relhandles = 0;
>
> switch(waitfor)
> {
> char clip[512];
> BOOL close;
>
> case WAIT_TIMEOUT:
> OutputDebugString(_T(" WAIT_TIMEOUT"));
> for(relhandles = 0; relhandles < curIns; relhandles++)
> {
> if(hThread[relhandles] !=0)
> {
>
> close = CloseHandle(hThread[relhandles]);
>
> if(close != 0)
> {
> sprintf(clip,_T("\n Handle %d closed \n"),relhandles);
> OutputDebugString(clip);
> }
> else
> {
> sprintf(clip,_T("\n Close Handle %d failed \n"),relhandles);
> OutputDebugString(clip);
> _Module.LogEvent(_T(clip));
> }
> }
> }
> break;
>
>
> case WAIT_ABANDONED_0:
>
> OutputDebugString(_T("WAIT_ABANDONED"));
> break;
>
> case WAIT_OBJECT_0:
> OutputDebugString(_T("WAIT_OBJECT_0"));
>
> for(relhandles = 0; relhandles < curIns; relhandles++)
> {
> if(hThread[relhandles] !=0)
> {
>
> close = CloseHandle(hThread[relhandles]);
>
> if(close != 0)
> {
> sprintf(clip,_T("\n Handle %d closed \n"),relhandles);
> OutputDebugString(clip);
> }
> else
> {
> sprintf(clip,_T("\n Close Handle %d failed \n"),relhandles);
> OutputDebugString(clip);
> _Module.LogEvent(_T(clip));
> }
> }
> }
> break;
> default:
> OutputDebugString(_T("default"));
>
> }
>
>
>
> thank you,
> vinod
>
>