[llvm] ae209aa - Fix memory leak in MicrosoftDemangleNodes's Node::toString

Raphael Isemann via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 22 09:44:45 PDT 2021


Author: Raphael Isemann
Date: 2021-04-22T18:44:30+02:00
New Revision: ae209aa9ecd717c0a73eebdb8ff16c5871b6f62f

URL: https://github.com/llvm/llvm-project/commit/ae209aa9ecd717c0a73eebdb8ff16c5871b6f62f
DIFF: https://github.com/llvm/llvm-project/commit/ae209aa9ecd717c0a73eebdb8ff16c5871b6f62f.diff

LOG: Fix memory leak in MicrosoftDemangleNodes's Node::toString

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.

Reviewed By: mstorsjo, rupprecht, MaskRay

Differential Revision: https://reviews.llvm.org/D100843

Added: 
    

Modified: 
    llvm/lib/Demangle/MicrosoftDemangleNodes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp b/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
index 0a3ba6d69ac99..9a64e2821be8f 100644
--- a/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -120,7 +120,9 @@ std::string Node::toString(OutputFlags Flags) const {
   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 {


        


More information about the llvm-commits mailing list