This is an archive of the discontinued LLVM Phabricator instance.

[libomptarget][amdgpu] fix memory leak in find_metadata
AbandonedPublic

Authored by ThorBl on Aug 5 2022, 6:51 AM.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Call to elf_memory had no corresponding elf_end calls. Added elf_end calls to deallocate the memory at every return point.

Diff Detail

Event Timeline

ThorBl created this revision.Aug 5 2022, 6:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 6:51 AM
ThorBl requested review of this revision.Aug 5 2022, 6:51 AM
ThorBl added a comment.Aug 5 2022, 7:04 AM

Received suggestion from Jonathan Chesterfield to use unique_ptrs.

@FabioLuporini might find this interesting, memory leak.

ThorBl updated this revision to Diff 451160.Aug 9 2022, 8:13 AM

Previous fix was incomplete. Two exit points were overlooked (did not contain calls to elf_end).

Regarding Jon's suggestion to replace elf_end() by std::unique_ptr:

The libelf.h header file contains only a forward declaration of the Elf struct. The declaration itself is hidden in libelfP.h, which is not accessible. This causes an 'incomplete type' error in unique_ptr's dtor. Without a doubt, using unique_ptr would be the preferred solution. However, since it is not easily possible to make the declaration of the struct available, I would stick with the calls to elf_end().

Missing context in the diff (see https://llvm.org/docs/Phabricator.html) and missing reviewers.

Would be better to put an object on the stack the calls elf_end in the destructor than to wire it up to all the paths.

I think @jhuber6 has a patch in flight which will collide with this

ThorBl abandoned this revision.Aug 10 2022, 7:12 AM

https://reviews.llvm.org/D131401 already addresses the problem.