[llvm] [Support] Fix memory leak induced by `sys::RemoveFileOnSignal` (PR #159984)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 21 08:15:38 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Alexandre Ganea (aganea)

<details>
<summary>Changes</summary>

Before this PR, `FilesToRemove` was constructed but never deleted.

---
Full diff: https://github.com/llvm/llvm-project/pull/159984.diff


1 Files Affected:

- (modified) llvm/lib/Support/Windows/Signals.inc (+6-1) 


``````````diff
diff --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc
index dad0fa3066868..db6d2eeb4169c 100644
--- a/llvm/lib/Support/Windows/Signals.inc
+++ b/llvm/lib/Support/Windows/Signals.inc
@@ -421,8 +421,13 @@ bool sys::RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg) {
     return true;
   }
 
-  if (FilesToRemove == NULL)
+  if (FilesToRemove == NULL) {
     FilesToRemove = new std::vector<std::string>;
+    std::atexit([]() {
+      delete FilesToRemove;
+      FilesToRemove = NULL;
+    });
+  }
 
   FilesToRemove->push_back(std::string(Filename));
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/159984


More information about the llvm-commits mailing list