BUG: make sure handles are always closed even if Wait is not called.
This commit is contained in:
parent
5573da922f
commit
e6e98b47da
|
@ -685,6 +685,52 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmWin32ProcessExecution::CloseHandles()
|
||||||
|
{
|
||||||
|
bool ret = true;
|
||||||
|
if (this->hChildStdinRd && !CloseHandle(this->hChildStdinRd))
|
||||||
|
{
|
||||||
|
m_Output += "CloseHandleError\n";
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
this->hChildStdinRd = 0;
|
||||||
|
if(this->hChildStdoutRdDup && !CloseHandle(this->hChildStdoutRdDup))
|
||||||
|
{
|
||||||
|
m_Output += "CloseHandleError\n";
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
this->hChildStdoutRdDup = 0;
|
||||||
|
if(this->hChildStderrRdDup && !CloseHandle(this->hChildStderrRdDup))
|
||||||
|
{
|
||||||
|
m_Output += "CloseHandleError\n";
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
this->hChildStderrRdDup = 0;
|
||||||
|
if(this->hChildStdinWrDup && !CloseHandle(this->hChildStdinWrDup))
|
||||||
|
{
|
||||||
|
m_Output += "CloseHandleError\n";
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
this->hChildStdinWrDup = 0;
|
||||||
|
if (this->hChildStdoutWr && !CloseHandle(this->hChildStdoutWr))
|
||||||
|
{
|
||||||
|
m_Output += "CloseHandleError\n";
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
this->hChildStdoutWr = 0;
|
||||||
|
if (this->hChildStderrWr && !CloseHandle(this->hChildStderrWr))
|
||||||
|
{
|
||||||
|
m_Output += "CloseHandleError\n";
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
this->hChildStderrWr = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
cmWin32ProcessExecution::~cmWin32ProcessExecution()
|
||||||
|
{
|
||||||
|
this->CloseHandles();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wrapper for fclose() to use for popen* files, so we can retrieve the
|
* Wrapper for fclose() to use for popen* files, so we can retrieve the
|
||||||
* exit code for the child process and return as a result of the close.
|
* exit code for the child process and return as a result of the close.
|
||||||
|
@ -806,41 +852,8 @@ bool cmWin32ProcessExecution::PrivateClose(int /* timeout */)
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
m_ExitValue = result;
|
m_ExitValue = result;
|
||||||
m_Output += output;
|
m_Output += output;
|
||||||
|
bool ret = this->CloseHandles();
|
||||||
if (this->hChildStdinRd && !CloseHandle(this->hChildStdinRd))
|
if ( result < 0 || !ret)
|
||||||
{
|
|
||||||
m_Output += "CloseHandleError\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(this->hChildStdoutRdDup && !CloseHandle(this->hChildStdoutRdDup))
|
|
||||||
{
|
|
||||||
m_Output += "CloseHandleError\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(this->hChildStderrRdDup && !CloseHandle(this->hChildStderrRdDup))
|
|
||||||
{
|
|
||||||
m_Output += "CloseHandleError\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(this->hChildStdinWrDup && !CloseHandle(this->hChildStdinWrDup))
|
|
||||||
{
|
|
||||||
m_Output += "CloseHandleError\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this->hChildStdoutWr && !CloseHandle(this->hChildStdoutWr))
|
|
||||||
{
|
|
||||||
m_Output += "CloseHandleError\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->hChildStderrWr && !CloseHandle(this->hChildStderrWr))
|
|
||||||
{
|
|
||||||
m_Output += "CloseHandleError\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ( result < 0 )
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
this->SetConsoleSpawn("w9xpopen.exe");
|
this->SetConsoleSpawn("w9xpopen.exe");
|
||||||
this->Initialize();
|
this->Initialize();
|
||||||
}
|
}
|
||||||
|
~cmWin32ProcessExecution();
|
||||||
///! If true windows will be created hidden.
|
///! If true windows will be created hidden.
|
||||||
void SetHideWindows(bool v) { m_HideWindows = v; }
|
void SetHideWindows(bool v) { m_HideWindows = v; }
|
||||||
|
|
||||||
|
@ -139,6 +140,7 @@ public:
|
||||||
int timeout, bool hideWindows);
|
int timeout, bool hideWindows);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool CloseHandles();
|
||||||
bool PrivateOpen(const char*, const char*, int, int);
|
bool PrivateOpen(const char*, const char*, int, int);
|
||||||
bool PrivateClose(int timeout);
|
bool PrivateClose(int timeout);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue