[Lldb-commits] [PATCH] D42409: Fix memory leaks in GoParser

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 23 00:01:16 PST 2018


teemperor created this revision.
teemperor added reviewers: labath, davide.

The GoParser is leaking memory in the tests due to not freeing allocated nodes when encountering some parsing errors. With this patch all GoParser tests are passing with enabled memory sanitizers/ubsan.


https://reviews.llvm.org/D42409

Files:
  source/Plugins/ExpressionParser/Go/GoParser.cpp


Index: source/Plugins/ExpressionParser/Go/GoParser.cpp
===================================================================
--- source/Plugins/ExpressionParser/Go/GoParser.cpp
+++ source/Plugins/ExpressionParser/Go/GoParser.cpp
@@ -439,8 +439,10 @@
   if (!type)
     return r.error();
   GoASTCompositeLit *lit = LiteralValue();
-  if (!lit)
+  if (!lit) {
+    delete type;
     return r.error();
+  }
   lit->SetType(type);
   return lit;
 }
@@ -548,6 +550,7 @@
 GoASTExpr *GoParser::Conversion() {
   Rule r("Conversion", this);
   if (GoASTExpr *t = Type2()) {
+    std::unique_ptr<GoASTExpr> owner(t);
     if (match(GoLexer::OP_LPAREN)) {
       GoASTExpr *v = Expression();
       if (!v)
@@ -557,6 +560,7 @@
         return r.error();
       GoASTCallExpr *call = new GoASTCallExpr(false);
       call->SetFun(t);
+      owner.release();
       call->AddArgs(v);
       return call;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42409.131007.patch
Type: text/x-patch
Size: 898 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180123/cad10148/attachment.bin>


More information about the lldb-commits mailing list