[clang] 6b1f7ba - [clang-repl] Fix leak when -mllvm parsing fails after #242861 (#242968)

via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 15 21:22:49 PST 2026


Author: Fangrui Song
Date: 2026-11-15T21:22:44-08:00
New Revision: 6b1f7ba6dd9ee47d2b2360447d1ab1aec16a3035

URL: https://github.com/llvm/llvm-project/commit/6b1f7ba6dd9ee47d2b2360447d1ab1aec16a3035
DIFF: https://github.com/llvm/llvm-project/commit/6b1f7ba6dd9ee47d2b2360447d1ab1aec16a3035.diff

LOG: [clang-repl] Fix leak when -mllvm parsing fails after #242861 (#242968)

Fix the InterpreterTest.BadLLVMArgs LeakSanitizer failure.

Added: 
    

Modified: 
    clang/lib/Interpreter/Interpreter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index dcb7824d270a1..429f9ee1cb345 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -232,8 +232,15 @@ static llvm::Error ExecuteIncrementalAction(CompilerInstance &CI,
   // LLVMContext.
   std::string Msg;
   llvm::raw_string_ostream OS(Msg);
-  if (!CI.parseLLVMArgs(&OS))
+  if (!CI.parseLLVMArgs(&OS)) {
+    // Without a preprocessor, the SourceManager never adopts the buffers.
+    PreprocessorOptions &PPOpts = CI.getPreprocessorOpts();
+    if (!PPOpts.RetainRemappedFileBuffers)
+      for (auto &RB : PPOpts.RemappedFileBuffers)
+        delete RB.second;
+    PPOpts.clearRemappedFiles();
     return llvm::createStringError(llvm::StringRef(Msg).rtrim());
+  }
   if (!CI.ExecuteAction(Act) || CI.getDiagnostics().hasErrorOccurred()) {
     return llvm::createStringError(llvm::errc::not_supported,
                                    "Failed to execute incremental action");


        


More information about the cfe-commits mailing list