[Mlir-commits] [mlir] 44b0b7c - Fix one memory leak in the MLIRParser by using std::unique_ptr to hold the new block pointer

Mehdi Amini llvmlistbot at llvm.org
Sat Jul 11 13:06:01 PDT 2020


Author: Mehdi Amini
Date: 2020-07-11T20:05:37Z
New Revision: 44b0b7cf6605c41728f445c363415b9b6f48db04

URL: https://github.com/llvm/llvm-project/commit/44b0b7cf6605c41728f445c363415b9b6f48db04
DIFF: https://github.com/llvm/llvm-project/commit/44b0b7cf6605c41728f445c363415b9b6f48db04.diff

LOG: 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

Added: 
    

Modified: 
    mlir/lib/Parser/Parser.cpp

Removed: 
    


################################################################################
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();
 


        


More information about the Mlir-commits mailing list