Skip to content

[Memprof] Fixes memory leak in MemInfoBlock histogram. #96834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/lib/ProfileData/MemProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bug which could happen elsewhere too. What do you think about adding a destructor to the MemInfoBlock which releases any allocated memory if the histogram size > 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I was thinking about that too. The problem is you want to keep the two files the same:

llvm/include/llvm/ProfileData/MemProfData.inc and
compiler-rt/include/profile/MemProfData.inc.

If you add the stuff in the destructor, they will have to diverge because they use different allocators (one with malloc, the other with InternalAlloc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we don't mind that they are not the exact same file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that makes sense. If we don't free the memory with delete (which is the case in the runtime) then it's not useful. Leaving as it is seems fine.

free((void*) CallstackProfileData[Id].AccessHistogram);
CallstackProfileData.erase(Id);
}

Expand Down
Loading