Author: teemperor
Date: Tue Jan 23 05:50:46 2018
New Revision: 323197

URL: http://llvm.org/viewvc/llvm-project?rev=323197&view=rev
Log:
Fix memory leaks in GoParser

Summary: 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.

Reviewers: labath, davide

Reviewed By: labath

Subscribers: lldb-commits

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

Modified:
    lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp

Modified: lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp?rev=323197&r1=323196&r2=323197&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp Tue Jan 23 
05:50:46 2018
@@ -439,8 +439,10 @@ GoASTExpr *GoParser::CompositeLit() {
   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::Arguments(GoASTExpr
 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 @@ GoASTExpr *GoParser::Conversion() {
         return r.error();
       GoASTCallExpr *call = new GoASTCallExpr(false);
       call->SetFun(t);
+      owner.release();
       call->AddArgs(v);
       return call;
     }


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to