[clang] [clang][modules] Close module file descriptors (PR #191227)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 9 09:03:13 PDT 2026
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/191227
This was missed in the original PR and was causing "too many files open" errors on real workloads.
>From 50cce4433cf51fc6779c556401e510eed490ad51 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Thu, 9 Apr 2026 09:01:37 -0700
Subject: [PATCH] [clang][modules] Close module file descriptors
---
clang/lib/Serialization/ModuleCache.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/lib/Serialization/ModuleCache.cpp b/clang/lib/Serialization/ModuleCache.cpp
index dd0b4b845331e..9ea4223a2eb83 100644
--- a/clang/lib/Serialization/ModuleCache.cpp
+++ b/clang/lib/Serialization/ModuleCache.cpp
@@ -10,6 +10,7 @@
#include "clang/Serialization/InMemoryModuleCache.h"
#include "clang/Serialization/ModuleFile.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/IOSandbox.h"
@@ -151,6 +152,7 @@ clang::readImpl(StringRef FileName, off_t &Size, time_t &ModTime) {
llvm::sys::fs::openNativeFileForRead(FileName);
if (!FD)
return FD.takeError();
+ llvm::scope_exit CloseFD([&FD]() { llvm::sys::fs::closeFile(*FD); });
llvm::sys::fs::file_status Status;
if (std::error_code EC = llvm::sys::fs::status(*FD, Status))
return llvm::errorCodeToError(EC);
More information about the cfe-commits
mailing list