<chrismorgan(a)rcn.com> wrote:
HANDLE hFile = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); BOOL ret = FALSE; + + if(!GetBinaryTypeA(filename, &binType)) /* determine what kind of binary this is */ + { + return FALSE; /* binary is not an executable */ + }
You are leaking the file handle here. Better move the GetBinaryTypeA call before the CreateFileA.
+ status = CreateProcessA (NULL, fullCmdLine, NULL, NULL, TRUE, + 0, envblock, NULL, &st, &pe); + + WaitForSingleObject(pe.hProcess, INFINITE); /* wait here until the child process is complete */ + + HeapFree(GetProcessHeap(), 0, fullCmdLine); /* free the memory we allocated */ + + /* clean up PROCESS_INFORMATION handles if necessary */ + if(status) + { + CloseHandle(pe.hProcess); + CloseHandle(pe.hThread); + }
Potential wait on an invalid pe.hProcess. Better: if (satus) { WaitForSingleObject(pe.hProcess, INFINITE); CloseHandle(pe.hProcess); CloseHandle(pe.hThread); } -- Dmitry.