summaryrefslogtreecommitdiff
path: root/Source/cmWin32ProcessExecution.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2005-01-17 14:29:11 -0500
committerBill Hoffman <bill.hoffman@kitware.com>2005-01-17 14:29:11 -0500
commite6e98b47da42835544fc817a44c43c9896994706 (patch)
tree6d0df0e96e897d5c93fa62d4eda10f4d978f25bb /Source/cmWin32ProcessExecution.cxx
parent5573da922f2354e6f8b098c04238b16a11cf9f03 (diff)
downloadcmake-e6e98b47da42835544fc817a44c43c9896994706.tar.gz
BUG: make sure handles are always closed even if Wait is not called.
Diffstat (limited to 'Source/cmWin32ProcessExecution.cxx')
-rw-r--r--Source/cmWin32ProcessExecution.cxx83
1 files changed, 48 insertions, 35 deletions
diff --git a/Source/cmWin32ProcessExecution.cxx b/Source/cmWin32ProcessExecution.cxx
index 6c9b05024d..78c54c2057 100644
--- a/Source/cmWin32ProcessExecution.cxx
+++ b/Source/cmWin32ProcessExecution.cxx
@@ -685,6 +685,52 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
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
* 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);
m_ExitValue = result;
m_Output += output;
-
- if (this->hChildStdinRd && !CloseHandle(this->hChildStdinRd))
- {
- 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 )
+ bool ret = this->CloseHandles();
+ if ( result < 0 || !ret)
{
return false;
}