Skip to content

Conversation

@aganea
Copy link
Member

@aganea aganea commented Sep 21, 2025

Before this PR, FilesToRemove was constructed but never deleted.

Before this PR, `FilesToRemove` was constructed but never deleted.
@llvmbot
Copy link
Member

llvmbot commented Sep 21, 2025

@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-llvm-support

Author: Alexandre Ganea (aganea)

Changes

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 --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));
 

}

if (FilesToRemove == NULL)
if (FilesToRemove == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can change FilesToRemove from static std::vector<std::string> *FilesToRemove = NULL; to static std::vector<std::string> FilesToRemove;, and change all pices where FilesToRemove == NULL to FilesToRemove.empty(), What do you think?

Copy link
Member Author

@aganea aganea Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that. However if we make it a non-pointer, and it is destroyed during global destruction; if any other subsequent global variable destructor code tries to access FilesToRemove after its destruction, that might crash in unexpected ways. Whereas here, as a pointer, it is clearly set to NULL and we already check if (FilesToRemove != NULL) in all the APIs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yes, it's may depends on globals destruct order.

Copy link
Contributor

@yronglin yronglin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@aganea aganea merged commit fe1491b into llvm:main Nov 1, 2025
12 checks passed
DEBADRIBASAK pushed a commit to DEBADRIBASAK/llvm-project that referenced this pull request Nov 3, 2025
…159984)

Before this PR, `FilesToRemove` was constructed but never deleted.
ckoparkar pushed a commit to ckoparkar/llvm-project that referenced this pull request Nov 6, 2025
…159984)

Before this PR, `FilesToRemove` was constructed but never deleted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants