process function cause handle leak?

Q&A's, tips, howto's

process function cause handle leak?

Postby iNPRwANG » Wed Apr 11, 2012 7:22 am

System is Windows xp, while loop call of the "process" function of newlisp 10.4.2, you may saw that the "Handle Count" of Task manager increment every call.

I have readed the source of win32-util.c:69, the "CreateProcess" systemcall return a PROCESS_INFORMATION
struct, the function call return the hProcess of this struct. I try to add a "CloseHandle" function call to close the hThread of this struct and recompile the newlisp, it looks work good.

Is this a leak? : )

Code: Select all

UINT winPipedProcess(char * cmd, int inpipe, int outpipe, int option)
{
STARTUPINFO si = { 0 };
PROCESS_INFORMATION process;
int result;
long fin, fout;

if(inpipe == -1 && outpipe == -1)
    {
    memset(&si, 0, sizeof(si));
    si.cb = sizeof(si);
    si.wShowWindow = option;
    memset(&process, 0, sizeof(process));
    }
else
    {
    /* GetStartupInfo(&si);  */
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    si.wShowWindow = option; /* SW_SHOW, SW_HIDE  get additional user option in Win32 versions */

    fin = _get_osfhandle(inpipe);
    fout = _get_osfhandle(outpipe);

    si.hStdInput = (inpipe) ? (HANDLE)fin : GetStdHandle(STD_INPUT_HANDLE);
    si.hStdOutput = (outpipe) ? (HANDLE)fout : GetStdHandle(STD_OUTPUT_HANDLE);
    si.hStdError = (outpipe) ? (HANDLE)fout : GetStdHandle(STD_OUTPUT_HANDLE);
    }

if((result = CreateProcess(NULL,cmd,NULL,NULL,TRUE,DETACHED_PROCESS,NULL,NULL,&si, &process)) == 0)
    return(0);
   
   //Try close hThread here
   CloseHandle(process.hThread);
return((UINT)process.hProcess);
}


iNPRwANG
 
Posts: 32
Joined: Sun May 08, 2011 1:45 pm

Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest

cron