From 6e6a0f50b3314b1d0e6e8706959bd29b57ecd5be Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 13 Jun 2013 15:27:17 +0000 Subject: [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. llvm-svn: 183906 --- llvm/lib/Support/Unix/Program.inc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'llvm/lib/Support/Unix/Program.inc') diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc index 0d6543a8a8c..d8bdd6ce424 100644 --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -178,7 +178,7 @@ static void SetMemoryLimits (unsigned size) } -static bool Execute(void *&Data, const Path &path, const char **args, +static bool Execute(void **Data, const Path &path, const char **args, const char **envp, const Path **redirects, unsigned memoryLimit, std::string *ErrMsg) { // If this OS has posix_spawn and there is no memory limit being implied, use @@ -228,7 +228,8 @@ static bool Execute(void *&Data, const Path &path, const char **args, if (Err) return !MakeErrMsg(ErrMsg, "posix_spawn failed", Err); - Data = reinterpret_cast(PID); + if (Data) + *Data = reinterpret_cast(PID); return true; } #endif @@ -290,7 +291,8 @@ static bool Execute(void *&Data, const Path &path, const char **args, break; } - Data = reinterpret_cast(child); + if (Data) + *Data = reinterpret_cast(child); return true; } @@ -299,11 +301,7 @@ static int Wait(void *&Data, const sys::Path &path, unsigned secondsToWait, std::string *ErrMsg) { #ifdef HAVE_SYS_WAIT_H struct sigaction Act, Old; - - if (Data == 0) { - MakeErrMsg(ErrMsg, "Process not started!"); - return -1; - } + assert(Data && "invalid pid to wait on, process not started?"); // Install a timeout handler. The handler itself does nothing, but the simple // fact of having a handler at all causes the wait below to return with EINTR, -- cgit v1.2.3