summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix/Program.inc
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2013-06-13 15:27:17 +0000
committerReid Kleckner <reid@kleckner.net>2013-06-13 15:27:17 +0000
commit6e6a0f50b3314b1d0e6e8706959bd29b57ecd5be (patch)
tree72b9b1d2347c870b42baf1f70f17eaf447c56834 /llvm/lib/Support/Unix/Program.inc
parent92509c1c0c8c9b3ad17aa265c2426a69ff0d0997 (diff)
downloadbcm5719-llvm-6e6a0f50b3314b1d0e6e8706959bd29b57ecd5be.tar.gz
bcm5719-llvm-6e6a0f50b3314b1d0e6e8706959bd29b57ecd5be.zip
[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
Diffstat (limited to 'llvm/lib/Support/Unix/Program.inc')
-rw-r--r--llvm/lib/Support/Unix/Program.inc14
1 files changed, 6 insertions, 8 deletions
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<void*>(PID);
+ if (Data)
+ *Data = reinterpret_cast<void*>(PID);
return true;
}
#endif
@@ -290,7 +291,8 @@ static bool Execute(void *&Data, const Path &path, const char **args,
break;
}
- Data = reinterpret_cast<void*>(child);
+ if (Data)
+ *Data = reinterpret_cast<void*>(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,
OpenPOWER on IntegriCloud