diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-09-18 19:25:11 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-09-18 19:25:11 +0000 |
commit | 622e220ca75478144eaa85e467c041f17f6b7324 (patch) | |
tree | 5b052538fe1caab5463e36eb46e1deb7d26adc1f /lib/System/Unix | |
parent | 62b442d3784c3d1c8468230c8df2bd853f763de8 (diff) |
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.cpp | 4 | ||||
-rw-r--r-- | 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 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; } |