Skip to content

Commit

Permalink
Fix memory leaks in GoParser
Browse files Browse the repository at this point in the history
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

llvm-svn: 323197
  • Loading branch information
Teemperor committed Jan 23, 2018
1 parent a67b366 commit b90f81e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lldb/source/Plugins/ExpressionParser/Go/GoParser.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -548,6 +550,7 @@ GoASTExpr *GoParser::Arguments(GoASTExpr *e) {
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)
Expand All @@ -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;
}
Expand Down

0 comments on commit b90f81e

Please sign in to comment.