From cdff5f77872bf57ed9f9b347e49ac08b9e87800e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 14 Mar 2010 23:16:45 +0000 Subject: 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 --- lib/System/Unix/Program.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/System') diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc index c10498a375..b4cc875df8 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 -- cgit v1.2.3-18-g5258