Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Handle-Leak in CreateProcess?

137 views
Skip to first unread message

Joerg Matysiak

unread,
Apr 22, 2003, 8:40:49 AM4/22/03
to
Hi,

I've got a problem with the CreateProcess() function - it seems
to allocate a second threadhandle on some versions of Windows.

My application periodically launches child applications and waits
for their termination.
On my development machine (NT Server, SP6), there's no problem,
but on the test machines (NT Workstation, SP6 and W2K Professional),
the handle count of the parent application increases each time a child
is created/terminated.

Using sysinternals process explorer, I found the following:

When CreateProcess is called, a thread- and a process-handle is created.
This is what happens on the NT server machine - on the other machines,
there is an additional threadhandle created, which cannot be closed,
because there's no way to get it returned. :(
(See the code for the test program below)

Has anyone seen this problem before?
Can anyone give me a hint how to aviod the creation of the third handle
or how to close this handle?

Thanks in advance,
Jörg

--------------------------- BEGIN SOURCE ------------------------
#include <windows.h>
#include <stdio.h>

static int wait()
{
int c;

printf("\n ... press ENTER ...\n");
fflush(stdout);
c = getc(stdin);
return(c);
}


int main (int argc, const char *argv[], const char *env[])
{
char *pcPrg = "ipconfig.exe";

for (;;)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

printf("going to start child");
wait();
// Start the child process.
if( !CreateProcess( NULL,
pcPrg, // call ipconfig
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi )
)
{
printf( "CreateProcess failed.\n" ); exit(1);
}
printf("child started"); wait();

// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );

printf("child terminated, cleaned up"); wait();
}

return(0);
}

--------------------------- END SOURCE ------------------------

Shailesh Humbad

unread,
Apr 25, 2003, 10:25:42 AM4/25/03
to
That's an interesting behaviour. I don't know the answer, but I checked
out the behaviour of my application on Windows XP Pro SP1, and it does
not create a third handle. It creates a process handle and thread
handle, and I close both of them immediately after the process starts.

The only thing I can suggest is if your processes are console mode
processes, you may have to specify some of the special creation flags
specified in the documentation.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/process_creation_flags.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp

Shailesh

Joerg Matysiak

unread,
Apr 30, 2003, 2:21:11 AM4/30/03
to
Hi and thanks for your help,

I found the problem-source: it's the "IBM Tivoli License Manager" service,
when this service is stopped, the problem doesn't occur any more :-)

Jörg

Shailesh Humbad <humb...@hotmail.com> wrote in message news:<Gzbqa.158434$0X.34...@twister.columbus.rr.com>...

354...@gmail.com

unread,
Dec 15, 2012, 6:35:23 AM12/15/12
to
Hi,
I've got the same problem, but there is no "IBM Tivoli License Manager" service in my computer. I guess the service is not the root of the problem. I don't know how to solve it.

在 2003年4月30日星期三UTC+8下午2时21分11秒,Joerg Matysiak写道:
0 new messages