[cfe-commits] r127639 - /cfe/trunk/lib/Basic/FileManager.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Mar 14 17:47:44 PDT 2011


Author: akirtzidis
Date: Mon Mar 14 19:47:44 2011
New Revision: 127639

URL: http://llvm.org/viewvc/llvm-project?rev=127639&view=rev
Log:
Stop leaking file descriptors.

After the open+fstat optimization, files were already opened for FileManager::getBufferForFile() and we closed them after reading them.
The problem was that when -working-directory was passed, the code path that actually reuses & closes the already opened file descriptor
was not followed.

Modified:
    cfe/trunk/lib/Basic/FileManager.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=127639&r1=127638&r2=127639&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Mon Mar 14 19:47:44 2011
@@ -466,21 +466,23 @@
 getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) {
   llvm::OwningPtr<llvm::MemoryBuffer> Result;
   llvm::error_code ec;
-  if (FileSystemOpts.WorkingDir.empty()) {
-    const char *Filename = Entry->getName();
-    // If the file is already open, use the open file descriptor.
-    if (Entry->FD != -1) {
-      ec = llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, Result,
-                                           Entry->getSize());
-      if (ErrorStr)
-        *ErrorStr = ec.message();
-
-      close(Entry->FD);
-      Entry->FD = -1;
-      return Result.take();
-    }
 
-    // Otherwise, open the file.
+  const char *Filename = Entry->getName();
+  // If the file is already open, use the open file descriptor.
+  if (Entry->FD != -1) {
+    ec = llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, Result,
+                                         Entry->getSize());
+    if (ErrorStr)
+      *ErrorStr = ec.message();
+
+    close(Entry->FD);
+    Entry->FD = -1;
+    return Result.take();
+  }
+
+  // Otherwise, open the file.
+
+  if (FileSystemOpts.WorkingDir.empty()) {
     ec = llvm::MemoryBuffer::getFile(Filename, Result, Entry->getSize());
     if (ec && ErrorStr)
       *ErrorStr = ec.message();





More information about the cfe-commits mailing list