From: Chris Lattner Date: Sun, 14 Mar 2010 23:16:45 +0000 (+0000) Subject: don't forget to close a FD on an error condition, found by X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=cdff5f77872bf57ed9f9b347e49ac08b9e87800e;p=oota-llvm.git don't forget to close a FD on an error condition, found by cppcheck, PR6617. Patch by Ettl Martin! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98525 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc index c10498a375a..b4cc875df8c 100644 --- a/lib/System/Unix/Program.inc +++ b/lib/System/Unix/Program.inc @@ -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