This is an archive of the discontinued LLVM Phabricator instance.

Fix memory leaks
AcceptedPublic

Authored by boleyn.su on Jul 1 2021, 7:48 AM.

Details

Summary

For vector<shared_ptr/unique_ptr>'s, emplace_back(new T()) is not
safe and can lead to memory leak. This happens when emplace_back
fails to allocate required memory and throws, and the object allocated
with new will never be deleted. Although this is not an issue
for LLVM as a compiler, it can hurt those who use it as a library.

Diff Detail

Event Timeline

boleyn.su created this revision.Jul 1 2021, 7:48 AM
boleyn.su requested review of this revision.Jul 1 2021, 7:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2021, 7:48 AM

Hi Chandler Carruth,
I found this bug in your slides at https://llvm.org/devmtg/2014-10/Slides/Carruth-TheLLVMPassManagerPart2.pdf.
I saw the same pattern somewhere else in the llvm repo too but I do not have the time and the tool to fix all of them.
I guess it would be much easier to fix it with the help of LLVM itself.
Hope this helps.
Boleyn Su

boleyn.su updated this revision to Diff 355881.Jul 1 2021, 7:53 AM

Fix a compile error :)

boleyn.su updated this revision to Diff 355887.Jul 1 2021, 8:07 AM

Fix a comiple error again :(

boleyn.su edited the summary of this revision. (Show Details)Jul 1 2021, 8:14 AM
boleyn.su edited the summary of this revision. (Show Details)
boleyn.su edited the summary of this revision. (Show Details)Jul 1 2021, 8:31 AM

Hi would you mind take a look at the patch?

Sent from https://boleyn.su/phone

chandlerc accepted this revision.Jul 27 2021, 8:16 PM
chandlerc added reviewers: asbirlea, aeubanks.
chandlerc added subscribers: aeubanks, asbirlea.

I don't think LLVM makes any attempt to be exception safe in this way, so not sure how important this is, but sure.

I don't work much on LLVM these days, so @asbirlea or @aeubanks may be better folks to reach out to for fixes here.

This revision is now accepted and ready to land.Jul 27 2021, 8:16 PM
boleyn.su requested review of this revision.Aug 8 2021, 7:05 AM

Thanks @chandlerc .

@asbirlea and @aeubanks would you mind to take at a look at the CL?

asbirlea accepted this revision.Aug 8 2021, 8:29 AM

Looks good to me as well.
Thought this patch would be good to go with Chandler's accept; for future similar fixes, myself and aeubanks are good contacts.

This revision is now accepted and ready to land.Aug 8 2021, 8:29 AM