[Support] Fix handle and memory leak for processes that are not waited for

Execute's Data parameter is now optional, so we won't allocate memory
for it on Windows and we'll close the process handle.

The Unix code should probably do something similar to avoid accumulation
of zombie children that haven't been waited on.

Tested on Linux and Windows.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183906 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner
2013-06-13 15:27:17 +00:00
parent 0db5f0f07e
commit 62d124a1fa
3 changed files with 27 additions and 40 deletions

View File

@ -22,7 +22,7 @@ using namespace sys;
//=== independent code.
//===----------------------------------------------------------------------===//
static bool Execute(void *&Data, const Path &path, const char **args,
static bool Execute(void **Data, const Path &path, const char **args,
const char **env, const sys::Path **redirects,
unsigned memoryLimit, std::string *ErrMsg);
@ -34,7 +34,7 @@ int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp,
unsigned memoryLimit, std::string *ErrMsg,
bool *ExecutionFailed) {
void *Data = 0;
if (Execute(Data, path, args, envp, redirects, memoryLimit, ErrMsg)) {
if (Execute(&Data, path, args, envp, redirects, memoryLimit, ErrMsg)) {
if (ExecutionFailed) *ExecutionFailed = false;
return Wait(Data, path, secondsToWait, ErrMsg);
}
@ -45,8 +45,7 @@ int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp,
void sys::ExecuteNoWait(const Path &path, const char **args, const char **envp,
const Path **redirects, unsigned memoryLimit,
std::string *ErrMsg) {
void *Data = 0;
Execute(Data, path, args, envp, redirects, memoryLimit, ErrMsg);
Execute(/*Data*/ 0, path, args, envp, redirects, memoryLimit, ErrMsg);
}
// Include the platform-specific parts of this class.