This is an archive of the discontinued LLVM Phabricator instance.

Fix memory leak in SBValue::GetAddress
AbandonedPublic

Authored by werat on Sep 24 2020, 10:04 AM.

Details

Summary

SBAddress constructor accepts a pointer to lldb_private::Address, but then dereferences it and copies the value. Allocating a temporary here leads to a memory leak.

Found via ASan:

Direct leak of 24 byte(s) in 1 object(s) allocated from:

#0 0x7fc70451e19f in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10919f)
#1 0x7fc6fdb560b4 in lldb::SBValue::GetAddress() /home/werat/git/llvm-project-upstream/lldb/source/API/SBValue.cpp:1359
#2 0x7fc6fdb06714 in lldb::SBType::operator=(lldb::SBType const&) /home/werat/git/llvm-project-upstream/lldb/source/API/SBType.cpp:83
...

Diff Detail

Event Timeline

werat created this revision.Sep 24 2020, 10:04 AM
werat requested review of this revision.Sep 24 2020, 10:04 AM

Good catch, thank you! I wanted to suggest making the SBAddress constructor take the Address by const-reference but wanted to see how much work that'd be which resulted in D88249.

JDevlieghere accepted this revision.Sep 24 2020, 10:58 AM

I meant to accept this, we can land this and deal with my suggestion as a follow up. LGTM.

This revision is now accepted and ready to land.Sep 24 2020, 10:58 AM
werat added a comment.Sep 25 2020, 6:07 AM

Thanks for reviewing and writing a follow-up change! Changing the ctor to accept a const reference is indeed a cleaner solution.

werat abandoned this revision.Nov 28 2020, 6:27 AM

Refactored in D88249 to avoid this problem altogether.