don't forget to close a FD on an error condition, found by
authorChris Lattner <sabre@nondot.org>
Sun, 14 Mar 2010 23:16:45 +0000 (23:16 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 14 Mar 2010 23:16:45 +0000 (23:16 +0000)
cppcheck, PR6617.  Patch by Ettl Martin!

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

lib/System/Unix/Program.inc

index c10498a375ac812e465bfc69828c0f9a52d4ca17..b4cc875df8c7765e691e0e39bef893e174834aab 100644 (file)
@@ -113,8 +113,9 @@ static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {
   }
 
   // Install it as the requested FD
-  if (-1 == dup2(InFD, FD)) {
+  if (dup2(InFD, FD) == -1) {
     MakeErrMsg(ErrMsg, "Cannot dup2");
+    close(InFD);
     return true;
   }
   close(InFD);      // Close the original FD