[Mlir-commits] [mlir] be5b844 - [mlir] fix memory leak on failure path in parser

Alex Zinenko llvmlistbot at llvm.org
Fri Mar 12 00:24:21 PST 2021


Author: Alex Zinenko
Date: 2021-03-12T09:24:08+01:00
New Revision: be5b844a354240007de05b67f6be7b48e1bbb25c

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

LOG: [mlir] fix memory leak on failure path in parser

Forward references to blocks lead to `Block`s being allocated in the
parser, but they are not necessarily included into a region if parsing
fails, leading to a leak. Clean them up in parser destructor.

Reviewed By: rriddle, mehdi_amini

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

Added: 
    

Modified: 
    mlir/lib/Parser/Parser.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 506aed57b4da..736522415b49 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -343,6 +343,14 @@ OperationParser::~OperationParser() {
     fwd.first.dropAllUses();
     fwd.first.getDefiningOp()->destroy();
   }
+  for (const auto &scope : forwardRef) {
+    for (const auto &fwd : scope) {
+      // Delete all blocks that were created as forward references but never
+      // included into a region.
+      fwd.first->dropAllUses();
+      delete fwd.first;
+    }
+  }
 }
 
 /// After parsing is finished, this function must be called to see if there are


        


More information about the Mlir-commits mailing list