Get rid of file descriptor leak in create_file.
authorReid Spencer <rspencer@reidspencer.com>
Sat, 18 Sep 2004 19:25:11 +0000 (19:25 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sat, 18 Sep 2004 19:25:11 +0000 (19:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16395 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Unix/Path.cpp
lib/System/Unix/Path.inc

index 182a0bbd8caf88291f6ec66779bd32f8c40a1f81..c9333decbfd64e1c573961b47dc511ffa1822b6b 100644 (file)
@@ -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;
 }
index 182a0bbd8caf88291f6ec66779bd32f8c40a1f81..c9333decbfd64e1c573961b47dc511ffa1822b6b 100644 (file)
@@ -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;
 }