diff options
author | Mehdi Amini <joker.eph@gmail.com> | 2020-07-11 23:05:37 +0300 |
---|---|---|
committer | Mehdi Amini <joker.eph@gmail.com> | 2020-07-11 23:05:37 +0300 |
commit | 44b0b7cf6605c41728f445c363415b9b6f48db04 (patch) | |
tree | 17c399fb66d0bbbefda93103705613e2fc242421 /mlir | |
parent | 3b04af4d84fbffa6a2e90cfd187ed01092b45684 (diff) |
Fix one memory leak in the MLIRParser by using std::unique_ptr to hold the new block pointer
This is NFC when there is no parsing error.
Differential Revision: https://reviews.llvm.org/D83619
Diffstat (limited to 'mlir')
-rw-r--r-- | mlir/lib/Parser/Parser.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 0e4589a20918..fc9d449ecc14 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -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()) { @@ -1519,7 +1520,6 @@ ParseResult OperationParser::parseRegion( } if (addDefinition(placeholderArgPair.first, block->addArgument(placeholderArgPair.second))) { - delete block; return failure(); } } @@ -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(); |