[mlir] Fixed memory leak after D141726.
authorSlava Zakharin <szakharin@nvidia.com>
Wed, 18 Jan 2023 03:25:23 +0000 (19:25 -0800)
committerSlava Zakharin <szakharin@nvidia.com>
Wed, 18 Jan 2023 05:34:46 +0000 (21:34 -0800)
Reported in https://lab.llvm.org/buildbot/#/builders/5/builds/30788

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

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

index 87eba6e..f069917 100644 (file)
@@ -1285,7 +1285,12 @@ LogicalResult ModuleTranslation::createTBAAMetadata() {
                            << refName << "'";
           return failure();
         }
+        auto *tempMD = cast<llvm::MDNode>(descNode->getOperand(opNum).get());
         descNode->replaceOperandWith(opNum, refNode);
+        // Deallocate temporary MDNode's explicitly.
+        // Note that each temporary node has a single use by creation,
+        // so it is valid to deallocate it here.
+        llvm::MDNode::deleteTemporary(tempMD);
       }
     }
   }