[llvm] [Support] Fix memory leak in `Timer.cpp` on shutdown (PR #159983)
    Fangrui Song via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sun Sep 21 10:07:03 PDT 2025
    
    
  
================
@@ -305,14 +306,24 @@ TimerGroup::~TimerGroup() {
     PrintQueuedTimers(*OutStream);
   }
 
+  auto unlink = [&]() {
+    *Prev = Next;
+    if (Next)
+      Next->Prev = Prev;
+  };
+
+  // If the managed instance is already dead, it means we're in the CRT
----------------
MaskRay wrote:
I am confused by this comment.
`llvm::TimerGroup::acquireTimerGlobals()` frees ManagedStatic. Is the leak due to timerLock() re-constructing the ManagedStatic?
https://github.com/llvm/llvm-project/pull/159983
    
    
More information about the llvm-commits
mailing list