This is an archive of the discontinued LLVM Phabricator instance.

Fix a memory leak found by check-lld asan tests.
ClosedPublic

Authored by krasin on Apr 5 2016, 5:14 PM.

Details

Summary

This bug was introduced by http://reviews.llvm.org/rL265059,
where InputSectionBase got Thunks field, which can do memory allocations.
Since InputSectionBase destructors were never called (I count it as another bug),
that caused a memory leak when 2 or more thunks are added to a section.

The fix to is properly call InputSectionBase destructors from ~ObjectFile.

Diff Detail

Event Timeline

krasin updated this revision to Diff 52747.Apr 5 2016, 5:14 PM
krasin retitled this revision from to Fix a memory leak found by check-lld asan tests..
krasin updated this object.
krasin added reviewers: atanasyan, rafael, ruiu.
krasin added subscribers: pcc, krasin.
rafael edited edge metadata.Apr 5 2016, 5:20 PM
rafael added a subscriber: rafael.

+ EHInputSection<ELFT> and MergeInputSection<ELFT> are allocated
+
using SpecificBumpPtrAllocator, which takes ownership.

Can't you do the same for InputSection? This would be the first
virtual function for the class.

Cheers,
Rafael

ruiu added inline comments.Apr 5 2016, 5:20 PM
ELF/InputFiles.h
114–125

This seems to be a bit too fragile. Generally, I prefer unique_ptr or SpecificBumpPtrAllocator or something like that over explicit destructors. Can you update InputFiles.cpp so that InputSection<ELFT> are allocated in the same way as EHInputSection<ELFT> or MergeInputSection<ELFT>? (i.e. using SpecificBumpPtrAllocator)

krasin added a comment.Apr 5 2016, 5:22 PM

Rafael, Rui,

thanks for the unison comments. Will do.

krasin updated this revision to Diff 52753.Apr 5 2016, 5:36 PM
krasin edited edge metadata.

Add SpecificBumpPtrAllocator for InputSection<ELFT>.

krasin marked an inline comment as done.Apr 5 2016, 5:37 PM

Done. Please, take a look.

rafael accepted this revision.Apr 5 2016, 6:08 PM
rafael edited edge metadata.

I think this is fine.

BTW, was this failing with an existing test with asan? If not, LGTM conditional on a test :-)

This revision is now accepted and ready to land.Apr 5 2016, 6:08 PM
krasin added a comment.Apr 5 2016, 6:12 PM

I think this is fine.

BTW, was this failing with an existing test with asan? If not, LGTM conditional on a test :-)

Oh, yes: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/11679/steps/check-lld%20asan/logs/stdio

I came to the fix, because of my sheriff duty to keep sanitizers bots green. :)

krasin closed this revision.Apr 5 2016, 6:16 PM
ruiu edited edge metadata.Apr 5 2016, 7:35 PM

LGTM