From 622e220ca75478144eaa85e467c041f17f6b7324 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sat, 18 Sep 2004 19:25:11 +0000 Subject: [PATCH] Get rid of file descriptor leak in create_file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16395 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/System/Unix/Path.cpp | 4 +++- lib/System/Unix/Path.inc | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/System/Unix/Path.cpp b/lib/System/Unix/Path.cpp index 182a0bbd8ca..c9333decbfd 100644 --- a/lib/System/Unix/Path.cpp +++ b/lib/System/Unix/Path.cpp @@ -377,8 +377,10 @@ Path::create_file() { if (!is_file()) return false; // Create the file - if (0 != creat(path.c_str(), S_IRUSR | S_IWUSR)) + int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR); + if (fd < 0) ThrowErrno(std::string(path.c_str()) + ": Can't create file"); + ::close(fd); return true; } diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index 182a0bbd8ca..c9333decbfd 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -377,8 +377,10 @@ Path::create_file() { if (!is_file()) return false; // Create the file - if (0 != creat(path.c_str(), S_IRUSR | S_IWUSR)) + int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR); + if (fd < 0) ThrowErrno(std::string(path.c_str()) + ": Can't create file"); + ::close(fd); return true; } -- 2.34.1