diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-03-15 00:47:44 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-03-15 00:47:44 +0000 |
commit | a8d530e3ad52cca33a81185ccc9518eab23ddb11 (patch) | |
tree | 37138bd19cd8a05679fce2584127dd0d8e8ef3aa /lib/Basic | |
parent | 112d5ee15a09f15e597037724e006004b3f2f78f (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127639 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic')
-rw-r--r-- | lib/Basic/FileManager.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 6512d76aae..9ad6e51a83 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -466,21 +466,23 @@ llvm::MemoryBuffer *FileManager:: 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(); |