Skip to content

Commit cb19ea4

Browse files
committed
[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.
1 parent 764c842 commit cb19ea4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

llvm/lib/Analysis/MustExecute.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,21 @@ ModulePass *llvm::createMustBeExecutedContextPrinter() {
355355

356356
bool MustBeExecutedContextPrinter::runOnModule(Module &M) {
357357
// We provide non-PM analysis here because the old PM doesn't like to query
358-
// function passes from a module pass. Given that this is a printer, we don't
359-
// care much about memory leaks.
360-
GetterTy<LoopInfo> LIGetter = [](const Function &F) {
358+
// function passes from a module pass.
359+
SmallVector<PostDominatorTree *, 8> PDTs;
360+
SmallVector<DominatorTree *, 8> DTs;
361+
SmallVector<LoopInfo *, 8> LIs;
362+
363+
GetterTy<LoopInfo> LIGetter = [&](const Function &F) {
361364
DominatorTree *DT = new DominatorTree(const_cast<Function &>(F));
362365
LoopInfo *LI = new LoopInfo(*DT);
366+
DTs.push_back(DT);
367+
LIs.push_back(LI);
363368
return LI;
364369
};
365-
GetterTy<PostDominatorTree> PDTGetter = [](const Function &F) {
370+
GetterTy<PostDominatorTree> PDTGetter = [&](const Function &F) {
366371
PostDominatorTree *PDT = new PostDominatorTree(const_cast<Function &>(F));
372+
PDTs.push_back(PDT);
367373
return PDT;
368374
};
369375
MustBeExecutedContextExplorer Explorer(true, LIGetter, PDTGetter);
@@ -376,6 +382,9 @@ bool MustBeExecutedContextPrinter::runOnModule(Module &M) {
376382
}
377383
}
378384

385+
DeleteContainerPointers(PDTs);
386+
DeleteContainerPointers(LIs);
387+
DeleteContainerPointers(DTs);
379388
return false;
380389
}
381390

0 commit comments

Comments
 (0)