[llvm] [Memprof] Fixes memory leak in MemInfoBlock histogram. (PR #96834)

Matthew Weingarten via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 26 17:07:31 PDT 2024


https://github.com/mattweingarten created https://github.com/llvm/llvm-project/pull/96834

MemInfoBlocks (MIB) with empty callstacks are erased prematurely from the CallStackProfileData. This patch frees allocated histogram buffers when the MIB is associated with an empty callstack.

>From 40ef303235b552037feed85eefb7721dc3673948 Mon Sep 17 00:00:00 2001
From: Matthew Weingarten <matt at weingarten.org>
Date: Thu, 27 Jun 2024 00:02:27 +0000
Subject: [PATCH] [Memprof] Fixes memory leak in MemInfoBlock histogram.

MemInfoBlocks (MIB) with empty callstacks are erased prematurely from the CallStackProfileData.
This patch frees allocated histogram buffers when the MIB is associated with an empty callstack.
---
 llvm/lib/ProfileData/MemProfReader.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index 85327273d6d7b..5e2d76e24dab7 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -633,6 +633,8 @@ Error RawMemProfReader::symbolizeAndFilterStackFrames(
   // Drop the entries where the callstack is empty.
   for (const uint64_t Id : EntriesToErase) {
     StackMap.erase(Id);
+    if(CallstackProfileData[Id].AccessHistogramSize > 0)
+      free((void*) CallstackProfileData[Id].AccessHistogram);
     CallstackProfileData.erase(Id);
   }
 



More information about the llvm-commits mailing list