This revision was automatically updated to reflect the committed changes. Closed by commit rL340188: Close FileEntries of cached files in ModuleManager::addModule(). (authored by adrian, committed by ).
Changed prior to commit: https://reviews.llvm.org/D50870?vs=161119&id=161501#toc Repository: rL LLVM https://reviews.llvm.org/D50870 Files: cfe/trunk/lib/Serialization/ModuleManager.cpp Index: cfe/trunk/lib/Serialization/ModuleManager.cpp =================================================================== --- cfe/trunk/lib/Serialization/ModuleManager.cpp +++ cfe/trunk/lib/Serialization/ModuleManager.cpp @@ -161,21 +161,24 @@ if (std::unique_ptr<llvm::MemoryBuffer> Buffer = lookupBuffer(FileName)) { // The buffer was already provided for us. NewModule->Buffer = &PCMCache->addBuffer(FileName, std::move(Buffer)); + // Since the cached buffer is reused, it is safe to close the file + // descriptor that was opened while stat()ing the PCM in + // lookupModuleFile() above, it won't be needed any longer. + Entry->closeFile(); } else if (llvm::MemoryBuffer *Buffer = PCMCache->lookupBuffer(FileName)) { NewModule->Buffer = Buffer; + // As above, the file descriptor is no longer needed. + Entry->closeFile(); } else { // Open the AST file. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf((std::error_code())); if (FileName == "-") { Buf = llvm::MemoryBuffer::getSTDIN(); } else { - // Leave the FileEntry open so if it gets read again by another - // ModuleManager it must be the same underlying file. - // FIXME: Because FileManager::getFile() doesn't guarantee that it will - // give us an open file, this may not be 100% reliable. + // Get a buffer of the file and close the file descriptor when done. Buf = FileMgr.getBufferForFile(NewModule->File, /*IsVolatile=*/false, - /*ShouldClose=*/false); + /*ShouldClose=*/true); } if (!Buf) {
Index: cfe/trunk/lib/Serialization/ModuleManager.cpp =================================================================== --- cfe/trunk/lib/Serialization/ModuleManager.cpp +++ cfe/trunk/lib/Serialization/ModuleManager.cpp @@ -161,21 +161,24 @@ if (std::unique_ptr<llvm::MemoryBuffer> Buffer = lookupBuffer(FileName)) { // The buffer was already provided for us. NewModule->Buffer = &PCMCache->addBuffer(FileName, std::move(Buffer)); + // Since the cached buffer is reused, it is safe to close the file + // descriptor that was opened while stat()ing the PCM in + // lookupModuleFile() above, it won't be needed any longer. + Entry->closeFile(); } else if (llvm::MemoryBuffer *Buffer = PCMCache->lookupBuffer(FileName)) { NewModule->Buffer = Buffer; + // As above, the file descriptor is no longer needed. + Entry->closeFile(); } else { // Open the AST file. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf((std::error_code())); if (FileName == "-") { Buf = llvm::MemoryBuffer::getSTDIN(); } else { - // Leave the FileEntry open so if it gets read again by another - // ModuleManager it must be the same underlying file. - // FIXME: Because FileManager::getFile() doesn't guarantee that it will - // give us an open file, this may not be 100% reliable. + // Get a buffer of the file and close the file descriptor when done. Buf = FileMgr.getBufferForFile(NewModule->File, /*IsVolatile=*/false, - /*ShouldClose=*/false); + /*ShouldClose=*/true); } if (!Buf) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits