[PATCH] D100843: Fix memory leak in MicrosoftDemangleNodes's Node::toString

Raphael Isemann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 20 05:01:32 PDT 2021


teemperor created this revision.
teemperor added reviewers: zturner, mstorsjo, erik.pilkington.
teemperor added a project: LLVM.
Herald added a subscriber: hiraditya.
teemperor requested review of this revision.
Herald added a subscriber: llvm-commits.

The buffer we turn into a std::string here is malloc'd and should be
free'd before we return from this function.

Follow up to LLDB leak fixes such as D100806 <https://reviews.llvm.org/D100806>.


https://reviews.llvm.org/D100843

Files:
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp


Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===================================================================
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -120,7 +120,9 @@
   initializeOutputStream(nullptr, nullptr, OS, 1024);
   this->output(OS, Flags);
   OS << '\0';
-  return {OS.getBuffer()};
+  std::string Owned(OS.getBuffer());
+  std::free(OS.getBuffer());
+  return Owned;
 }
 
 void PrimitiveTypeNode::outputPre(OutputStream &OS, OutputFlags Flags) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100843.338818.patch
Type: text/x-patch
Size: 534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210420/a76daeca/attachment.bin>


More information about the llvm-commits mailing list