Skip to content

Commit 87f0dd3

Browse files
jmorsetstellar
authored andcommitted
Follow up to 9fd9d56, avoid a memory leak
Gaps in the basic block number range (from blocks being deleted or folded) get block-value-tables allocated but never ejected, leading to a memory leak, currently tripping up the asan buildbots. Fix this up by manually freeing that memory. As suggested elsewhere, if these things were owned by a unique_ptr then cleanup would happen automagically. D118774 should eliminate the need for this dance. (cherry picked from commit 206cafb)
1 parent 89d7063 commit 87f0dd3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,16 @@ bool InstrRefBasedLDV::depthFirstVLocAndEmit(
30273027
if (MOutLocs[MBB->getNumber()])
30283028
EjectBlock(*MBB);
30293029

3030+
// Finally, there might have been gaps in the block numbering, from dead
3031+
// blocks being deleted or folded. In those scenarios, we might allocate a
3032+
// block-table that's never ejected, meaning we have to free it at the end.
3033+
for (unsigned int I = 0; I < MaxNumBlocks; ++I) {
3034+
if (MInLocs[I]) {
3035+
delete[] MInLocs[I];
3036+
delete[] MOutLocs[I];
3037+
}
3038+
}
3039+
30303040
return emitTransfers(AllVarsNumbering);
30313041
}
30323042

0 commit comments

Comments
 (0)