diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2004-09-07 20:03:25 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2004-09-07 20:03:25 (GMT) |
commit | 8f92e8c069dcb3cb943144864274ee75bad36c0d (patch) | |
tree | 90b594cabea3a20d3c62f7f9f99916264dfe9500 /Source | |
parent | 2c4b1a1179b148505e22f7816f2b8e90974052c7 (diff) | |
download | CMake-8f92e8c069dcb3cb943144864274ee75bad36c0d.zip CMake-8f92e8c069dcb3cb943144864274ee75bad36c0d.tar.gz CMake-8f92e8c069dcb3cb943144864274ee75bad36c0d.tar.bz2 |
Fix leaked file and registry descriptors
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmWin32ProcessExecution.cxx | 72 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 2 |
2 files changed, 17 insertions, 57 deletions
diff --git a/Source/cmWin32ProcessExecution.cxx b/Source/cmWin32ProcessExecution.cxx index 1522cda..e4ee523 100644 --- a/Source/cmWin32ProcessExecution.cxx +++ b/Source/cmWin32ProcessExecution.cxx @@ -490,7 +490,6 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring, SECURITY_ATTRIBUTES saAttr; BOOL fSuccess; int fd1, fd2, fd3; - //FILE *f1, *f2, *f3; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; @@ -570,42 +569,30 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring, case _O_WRONLY | _O_TEXT: /* Case for writing to child Stdin in text mode. */ fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); - //f1 = _fdopen(fd1, "w"); /* We don't care about these pipes anymore, so close them. */ - CloseHandle(hChildStdoutRdDup); - CloseHandle(hChildStderrRdDup); break; case _O_RDONLY | _O_TEXT: /* Case for reading from child Stdout in text mode. */ fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); - //f1 = _fdopen(fd1, "r"); /* We don't care about these pipes anymore, so close them. */ - CloseHandle(hChildStdinWrDup); - CloseHandle(hChildStderrRdDup); break; case _O_RDONLY | _O_BINARY: /* Case for readinig from child Stdout in binary mode. */ fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); - //f1 = _fdopen(fd1, "rb"); /* We don't care about these pipes anymore, so close them. */ - CloseHandle(hChildStdinWrDup); - CloseHandle(hChildStderrRdDup); break; case _O_WRONLY | _O_BINARY: /* Case for writing to child Stdin in binary mode. */ fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); - //f1 = _fdopen(fd1, "wb"); /* We don't care about these pipes anymore, so close them. */ - CloseHandle(hChildStdoutRdDup); - CloseHandle(hChildStderrRdDup); break; } break; @@ -614,60 +601,17 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring, case POPEN_4: if ( 1 ) { - // Comment this out. Maybe we will need it in the future. - // file IO access to the process might be cool. - //char *m1, *m2; - - //if (mode && _O_TEXT) - // { - // m1 = "r"; - // m2 = "w"; - // } - //else - // { - // m1 = "rb"; - // m2 = "wb"; - // } - fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); - //f1 = _fdopen(fd1, m2); fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); - //f2 = _fdopen(fd2, m1); - - if (n != 4) - { - CloseHandle(hChildStderrRdDup); - } - break; } case POPEN_3: if ( 1) { - // Comment this out. Maybe we will need it in the future. - // file IO access to the process might be cool. - //char *m1, *m2; - - //if (mode && _O_TEXT) - // { - // m1 = "r"; - // m2 = "w"; - // } - //else - // { - // m1 = "rb"; - // m2 = "wb"; - // } - - fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); - //f1 = _fdopen(fd1, m2); fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); - //f2 = _fdopen(fd2, m1); fd3 = _open_osfhandle(TO_INTPTR(hChildStderrRdDup), mode); - //f3 = _fdopen(fd3, m1); - break; } } @@ -720,7 +664,21 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring, m_Output += "CloseHandleError\n"; return false; } - + if(!CloseHandle(hChildStdoutRdDup)) + { + m_Output += "CloseHandleError\n"; + return false; + } + if(!CloseHandle(hChildStderrRdDup)) + { + m_Output += "CloseHandleError\n"; + return false; + } + if(!CloseHandle(hChildStdinWrDup)) + { + m_Output += "CloseHandleError\n"; + return false; + } if (!CloseHandle(hChildStdoutWr)) { m_Output += "CloseHandleError\n"; diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 2ab0895..3f6ee37 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -401,6 +401,7 @@ bool SystemTools::ReadRegistryValue(const char *key, kwsys_stl::string &value) if (dwType == REG_SZ) { value = data; + RegCloseKey(hKey); return true; } } @@ -564,6 +565,7 @@ bool SystemTools::DeleteRegistryValue(const char *key) if(RegDeleteValue(hKey, (LPTSTR)valuename.c_str()) == ERROR_SUCCESS) { + RegCloseKey(hKey); return true; } } |