summaryrefslogtreecommitdiff
path: root/lib/System/Unix
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-09-18 19:25:11 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-09-18 19:25:11 +0000
commit622e220ca75478144eaa85e467c041f17f6b7324 (patch)
tree5b052538fe1caab5463e36eb46e1deb7d26adc1f /lib/System/Unix
parent62b442d3784c3d1c8468230c8df2bd853f763de8 (diff)
downloadllvm-622e220ca75478144eaa85e467c041f17f6b7324.tar.gz
llvm-622e220ca75478144eaa85e467c041f17f6b7324.tar.bz2
llvm-622e220ca75478144eaa85e467c041f17f6b7324.tar.xz
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
Diffstat (limited to 'lib/System/Unix')
-rw-r--r--lib/System/Unix/Path.cpp4
-rw-r--r--lib/System/Unix/Path.inc4
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/System/Unix/Path.cpp b/lib/System/Unix/Path.cpp
index 182a0bbd8c..c9333decbf 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 182a0bbd8c..c9333decbf 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;
}