summaryrefslogtreecommitdiff
path: root/lib/Support/Unix
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
commit62d124a1fa8b212bae1d331f027c9eec06a45199 (patch)
treed54ab55c93830ef075514d681167fd86d9fd81e9 /lib/Support/Unix
parent0db5f0f07e6411fa25aefd464648ec8fc335a2d7 (diff)
downloadllvm-62d124a1fa8b212bae1d331f027c9eec06a45199.tar.gz
llvm-62d124a1fa8b212bae1d331f027c9eec06a45199.tar.bz2
llvm-62d124a1fa8b212bae1d331f027c9eec06a45199.tar.xz
[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
Diffstat (limited to 'lib/Support/Unix')
-rw-r--r--lib/Support/Unix/Program.inc14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc
index 0d6543a8a8..d8bdd6ce42 100644
--- a/lib/Support/Unix/Program.inc
+++ b/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,