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.

llvm-svn: 127639
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 6512d76..9ad6e51 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -466,21 +466,23 @@
 getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) {
   llvm::OwningPtr<llvm::MemoryBuffer> Result;
   llvm::error_code ec;
+
+  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()) {
-    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.
     ec = llvm::MemoryBuffer::getFile(Filename, Result, Entry->getSize());
     if (ec && ErrorStr)
       *ErrorStr = ec.message();