[llvm] cb19ea4 - [FIX] Make LSan happy by *not* leaking memory

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 10:17:41 PDT 2019


Author: Johannes Doerfert
Date: 2019-10-31T12:16:54-05:00
New Revision: cb19ea45a71b74c72ad5e8ceaa42a0b6c8168576

URL: https://github.com/llvm/llvm-project/commit/cb19ea45a71b74c72ad5e8ceaa42a0b6c8168576
DIFF: https://github.com/llvm/llvm-project/commit/cb19ea45a71b74c72ad5e8ceaa42a0b6c8168576.diff

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

I left a memory leak in a printer pass which made LSan sad so I remove
the memory leak now to make LSan happy.

Reported and tested by vlad.tsyrklevich.

Added: 
    

Modified: 
    llvm/lib/Analysis/MustExecute.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp
index 585c984a00fb..4c4cdcbbec2e 100644
--- a/llvm/lib/Analysis/MustExecute.cpp
+++ b/llvm/lib/Analysis/MustExecute.cpp
@@ -355,15 +355,21 @@ ModulePass *llvm::createMustBeExecutedContextPrinter() {
 
 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 @@ bool MustBeExecutedContextPrinter::runOnModule(Module &M) {
     }
   }
 
+  DeleteContainerPointers(PDTs);
+  DeleteContainerPointers(LIs);
+  DeleteContainerPointers(DTs);
   return false;
 }
 


        


More information about the llvm-commits mailing list