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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-pgo

Author: Matthew Weingarten (mattweingarten)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/96834.diff


1 Files Affected:

- (modified) llvm/lib/ProfileData/MemProfReader.cpp (+2) 


``````````diff
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);
   }
 

``````````

</details>


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


More information about the llvm-commits mailing list