[llvm] [Support] Fix memory leak induced by `sys::RemoveFileOnSignal` (PR #159984)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 21 08:15:05 PDT 2025
https://github.com/aganea created https://github.com/llvm/llvm-project/pull/159984
Before this PR, `FilesToRemove` was constructed but never deleted.
>From 6778477f3aa51fefa54e21c6e3f699ddd3405d3c Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <alex_toresh at yahoo.fr>
Date: Sun, 21 Sep 2025 11:12:48 -0400
Subject: [PATCH] [Support] Fix memory leak induced by
`sys::RemoveFileOnSignal`
Before this PR, `FilesToRemove` was constructed but never deleted.
---
llvm/lib/Support/Windows/Signals.inc | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
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));
More information about the llvm-commits
mailing list