Skip to content

Commit

Permalink
Fix one memory leak in the MLIRParser by using std::unique_ptr to hol…
Browse files Browse the repository at this point in the history
…d the new block pointer

 This is NFC when there is no parsing error.

Differential Revision: https://reviews.llvm.org/D83619
  • Loading branch information
joker-eph committed Jul 11, 2020
1 parent 3b04af4 commit 44b0b7c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions mlir/lib/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,8 @@ ParseResult OperationParser::parseRegion(
pushSSANameScope(isIsolatedNameScope);

// Parse the first block directly to allow for it to be unnamed.
Block *block = new Block();
auto owning_block = std::make_unique<Block>();
Block *block = owning_block.get();

// Add arguments to the entry block.
if (!entryArguments.empty()) {
Expand All @@ -1519,7 +1520,6 @@ ParseResult OperationParser::parseRegion(
}
if (addDefinition(placeholderArgPair.first,
block->addArgument(placeholderArgPair.second))) {
delete block;
return failure();
}
}
Expand All @@ -1530,19 +1530,17 @@ ParseResult OperationParser::parseRegion(
}

if (parseBlock(block)) {
delete block;
return failure();
}

// Verify that no other arguments were parsed.
if (!entryArguments.empty() &&
block->getNumArguments() > entryArguments.size()) {
delete block;
return emitError("entry block arguments were already defined");
}

// Parse the rest of the region.
region.push_back(block);
region.push_back(owning_block.release());
if (parseRegionBody(region))
return failure();

Expand Down

0 comments on commit 44b0b7c

Please sign in to comment.