[PATCH] D57094: Fix memory leak in ManagedStatic

Andrzej Ratajewski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 23 04:53:04 PST 2019


aratajew created this revision.
aratajew added reviewers: chandlerc, chapuni.
Herald added subscribers: llvm-commits, kristina.

ManagedStaticMutex is allocated once we call getManagedStaticMutex, but it is nowhere deallocated.


Repository:
  rL LLVM

https://reviews.llvm.org/D57094

Files:
  lib/Support/ManagedStatic.cpp


Index: lib/Support/ManagedStatic.cpp
===================================================================
--- lib/Support/ManagedStatic.cpp
+++ lib/Support/ManagedStatic.cpp
@@ -77,8 +77,13 @@
 
 /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
 void llvm::llvm_shutdown() {
-  MutexGuard Lock(*getManagedStaticMutex());
+  {
+    MutexGuard Lock(*getManagedStaticMutex());
+
+    while (StaticList)
+      StaticList->destroy();
+  }
 
-  while (StaticList)
-    StaticList->destroy();
+  delete ManagedStaticMutex;
+  ManagedStaticMutex = nullptr;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57094.183086.patch
Type: text/x-patch
Size: 575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190123/ff4fbe2a/attachment.bin>


More information about the llvm-commits mailing list