[PATCH] D69674: [FIX] Make LSan happy by *not* leaking memory

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 10:12:19 PDT 2019


jdoerfert updated this revision to Diff 227305.
jdoerfert added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69674/new/

https://reviews.llvm.org/D69674

Files:
  llvm/lib/Analysis/MustExecute.cpp


Index: llvm/lib/Analysis/MustExecute.cpp
===================================================================
--- llvm/lib/Analysis/MustExecute.cpp
+++ llvm/lib/Analysis/MustExecute.cpp
@@ -355,15 +355,21 @@
 
 bool MustBeExecutedContextPrinter::runOnModule(Module &M) {
   // We provide non-PM analysis here because the old PM doesn't like to query
-  // function passes from a module pass. Given that this is a printer, we don't
-  // care much about memory leaks.
-  GetterTy<LoopInfo> LIGetter = [](const Function &F) {
+  // function passes from a module pass.
+  SmallVector<PostDominatorTree *, 8> PDTs;
+  SmallVector<DominatorTree *, 8> DTs;
+  SmallVector<LoopInfo *, 8> LIs;
+
+  GetterTy<LoopInfo> LIGetter = [&](const Function &F) {
     DominatorTree *DT = new DominatorTree(const_cast<Function &>(F));
     LoopInfo *LI = new LoopInfo(*DT);
+    DTs.push_back(DT);
+    LIs.push_back(LI);
     return LI;
   };
-  GetterTy<PostDominatorTree> PDTGetter = [](const Function &F) {
+  GetterTy<PostDominatorTree> PDTGetter = [&](const Function &F) {
     PostDominatorTree *PDT = new PostDominatorTree(const_cast<Function &>(F));
+    PDTs.push_back(PDT);
     return PDT;
   };
   MustBeExecutedContextExplorer Explorer(true, LIGetter, PDTGetter);
@@ -376,6 +382,9 @@
     }
   }
 
+  DeleteContainerPointers(PDTs);
+  DeleteContainerPointers(LIs);
+  DeleteContainerPointers(DTs);
   return false;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69674.227305.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191031/a33da8b6/attachment.bin>


More information about the llvm-commits mailing list