[Lldb-commits] [PATCH] D88247: Fix memory leak in SBValue::GetAddress

Andy Yankovsky via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 24 10:04:42 PDT 2020

werat created this revision.
werat added a reviewer: labath.
werat added a project: LLDB.
Herald added subscribers: lldb-commits, JDevlieghere.
Herald added a reviewer: JDevlieghere.
werat requested review of this revision.

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

  rG LLVM Github Monorepo



Index: lldb/source/API/SBValue.cpp
--- lldb/source/API/SBValue.cpp
+++ lldb/source/API/SBValue.cpp
@@ -1356,7 +1356,7 @@
-  return LLDB_RECORD_RESULT(SBAddress(new Address(addr)));
+  return LLDB_RECORD_RESULT(SBAddress(&addr));
 lldb::SBData SBValue::GetPointeeData(uint32_t item_idx, uint32_t item_count) {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88247.294101.patch
Type: text/x-patch
Size: 396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200924/d85896fe/attachment.bin>

More information about the lldb-commits mailing list