From: Yaron Keren <yaron.keren@gmail.com>
Date: Fri, 17 Apr 2015 12:11:15 +0000 (+0000)
Subject: Revert r235177 as the Handle is used to fail GetExitCodeProcess on purpose.
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=dc71d8a7b95d642f26243d10eda86f33e7a6f6ba;p=oota-llvm.git

Revert r235177 as the Handle is used to fail GetExitCodeProcess on purpose.
Avoid double closing of the handle by testing GetLastErr for
ERROR_INVALID_HANDLE and not calling CloseHandle(PI.ProcessHandle) then.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235184 91177308-0d34-0410-b5e6-96231b3b80d8
---

diff --git a/lib/Support/Windows/Program.inc b/lib/Support/Windows/Program.inc
index 32602345f65..75685de4554 100644
--- a/lib/Support/Windows/Program.inc
+++ b/lib/Support/Windows/Program.inc
@@ -423,6 +423,7 @@ ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
         return WaitResult;
       }
       WaitForSingleObject(PI.ProcessHandle, INFINITE);
+      CloseHandle(PI.ProcessHandle);
     } else {
       // Non-blocking wait.
       return ProcessInfo();
@@ -433,7 +434,8 @@ ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
   DWORD status;
   BOOL rc = GetExitCodeProcess(PI.ProcessHandle, &status);
   DWORD err = GetLastError();
-  CloseHandle(PI.ProcessHandle);
+  if (err != ERROR_INVALID_HANDLE)
+    CloseHandle(PI.ProcessHandle);
 
   if (!rc) {
     SetLastError(err);