[llvm-branch-commits] [llvm] 87f0dd3 - Follow up to 9fd9d56dc6b, avoid a memory leak

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 7 13:27:07 PST 2022


Author: Jeremy Morse
Date: 2022-02-07T13:26:39-08:00
New Revision: 87f0dd330eaa089ca4034dffc105a7f2eef6b90c

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

LOG: Follow up to 9fd9d56dc6b, 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 206cafb680cea0741f8c7b276351db516ff27f81)

Added: 
    

Modified: 
    llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 268095e0943a0..cc800736a2dc1 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -3027,6 +3027,16 @@ bool InstrRefBasedLDV::depthFirstVLocAndEmit(
     if (MOutLocs[MBB->getNumber()])
       EjectBlock(*MBB);
 
+  // Finally, there might have been gaps in the block numbering, from dead
+  // blocks being deleted or folded. In those scenarios, we might allocate a
+  // block-table that's never ejected, meaning we have to free it at the end.
+  for (unsigned int I = 0; I < MaxNumBlocks; ++I) {
+    if (MInLocs[I]) {
+      delete[] MInLocs[I];
+      delete[] MOutLocs[I];
+    }
+  }
+
   return emitTransfers(AllVarsNumbering);
 }
 


        


More information about the llvm-branch-commits mailing list