Fix leaked file and registry descriptors

This commit is contained in:
Bill Hoffman 2004-09-07 16:03:25 -04:00
parent 2c4b1a1179
commit 8f92e8c069
2 changed files with 17 additions and 57 deletions

View File

@ -490,7 +490,6 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
SECURITY_ATTRIBUTES saAttr; SECURITY_ATTRIBUTES saAttr;
BOOL fSuccess; BOOL fSuccess;
int fd1, fd2, fd3; int fd1, fd2, fd3;
//FILE *f1, *f2, *f3;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE; saAttr.bInheritHandle = TRUE;
@ -570,42 +569,30 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
case _O_WRONLY | _O_TEXT: case _O_WRONLY | _O_TEXT:
/* Case for writing to child Stdin in text mode. */ /* Case for writing to child Stdin in text mode. */
fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode);
//f1 = _fdopen(fd1, "w");
/* We don't care about these pipes anymore, /* We don't care about these pipes anymore,
so close them. */ so close them. */
CloseHandle(hChildStdoutRdDup);
CloseHandle(hChildStderrRdDup);
break; break;
case _O_RDONLY | _O_TEXT: case _O_RDONLY | _O_TEXT:
/* Case for reading from child Stdout in text mode. */ /* Case for reading from child Stdout in text mode. */
fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode);
//f1 = _fdopen(fd1, "r");
/* We don't care about these pipes anymore, /* We don't care about these pipes anymore,
so close them. */ so close them. */
CloseHandle(hChildStdinWrDup);
CloseHandle(hChildStderrRdDup);
break; break;
case _O_RDONLY | _O_BINARY: case _O_RDONLY | _O_BINARY:
/* Case for readinig from child Stdout in /* Case for readinig from child Stdout in
binary mode. */ binary mode. */
fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode);
//f1 = _fdopen(fd1, "rb");
/* We don't care about these pipes anymore, /* We don't care about these pipes anymore,
so close them. */ so close them. */
CloseHandle(hChildStdinWrDup);
CloseHandle(hChildStderrRdDup);
break; break;
case _O_WRONLY | _O_BINARY: case _O_WRONLY | _O_BINARY:
/* Case for writing to child Stdin in binary mode. */ /* Case for writing to child Stdin in binary mode. */
fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode);
//f1 = _fdopen(fd1, "wb");
/* We don't care about these pipes anymore, /* We don't care about these pipes anymore,
so close them. */ so close them. */
CloseHandle(hChildStdoutRdDup);
CloseHandle(hChildStderrRdDup);
break; break;
} }
break; break;
@ -614,60 +601,17 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
case POPEN_4: case POPEN_4:
if ( 1 ) 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); fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode);
//f1 = _fdopen(fd1, m2);
fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode);
//f2 = _fdopen(fd2, m1);
if (n != 4)
{
CloseHandle(hChildStderrRdDup);
}
break; break;
} }
case POPEN_3: case POPEN_3:
if ( 1) 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); fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode);
//f1 = _fdopen(fd1, m2);
fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode);
//f2 = _fdopen(fd2, m1);
fd3 = _open_osfhandle(TO_INTPTR(hChildStderrRdDup), mode); fd3 = _open_osfhandle(TO_INTPTR(hChildStderrRdDup), mode);
//f3 = _fdopen(fd3, m1);
break; break;
} }
} }
@ -720,7 +664,21 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
m_Output += "CloseHandleError\n"; m_Output += "CloseHandleError\n";
return false; 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)) if (!CloseHandle(hChildStdoutWr))
{ {
m_Output += "CloseHandleError\n"; m_Output += "CloseHandleError\n";

View File

@ -401,6 +401,7 @@ bool SystemTools::ReadRegistryValue(const char *key, kwsys_stl::string &value)
if (dwType == REG_SZ) if (dwType == REG_SZ)
{ {
value = data; value = data;
RegCloseKey(hKey);
return true; return true;
} }
} }
@ -564,6 +565,7 @@ bool SystemTools::DeleteRegistryValue(const char *key)
if(RegDeleteValue(hKey, if(RegDeleteValue(hKey,
(LPTSTR)valuename.c_str()) == ERROR_SUCCESS) (LPTSTR)valuename.c_str()) == ERROR_SUCCESS)
{ {
RegCloseKey(hKey);
return true; return true;
} }
} }