From f8af7ea99a5d27bbc7bb0167e8e4ecc309b33fd4 Mon Sep 17 00:00:00 2001 From: hanr881 <1741282579@qq.com> Date: Wed, 26 Jul 2023 08:48:34 +0000 Subject: [PATCH] to issue<50473724>:fix cursor open memory leak --- src/pl/ob_pl_resolver.cpp | 2 ++ src/pl/ob_pl_stmt.h | 11 +++++++++++ src/sql/ob_spi.cpp | 1 + src/sql/ob_spi.h | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/src/pl/ob_pl_resolver.cpp b/src/pl/ob_pl_resolver.cpp index c12ff5c651..863efb1d7e 100644 --- a/src/pl/ob_pl_resolver.cpp +++ b/src/pl/ob_pl_resolver.cpp @@ -13672,6 +13672,8 @@ int ObPLResolver::resolve_stmt_list(const ObStmtNodeTree *node, } if (OB_SUCC(ret)) { set_current(*parent); + } else if (block != NULL) { + block->reset(); } } return ret; diff --git a/src/pl/ob_pl_stmt.h b/src/pl/ob_pl_stmt.h index bf8ed3e32c..440dae842c 100644 --- a/src/pl/ob_pl_stmt.h +++ b/src/pl/ob_pl_stmt.h @@ -1912,11 +1912,17 @@ public: is_contain_goto_stmt_(false), is_autonomous_block_(false) {} virtual ~ObPLStmtBlock() { + reset(); + } + + void reset() + { for (int64_t i = 0; i < stmts_.count(); ++i) { if (NULL != stmts_.at(i)) { stmts_.at(i)->~ObPLStmt(); } } + stmts_.reset(); } int accept(ObPLStmtVisitor &visitor) const; @@ -2040,9 +2046,11 @@ public: virtual ~ObPLIfStmt() { if (NULL != then_) { then_->~ObPLStmtBlock(); + then_ = NULL; } if (NULL != else_) { else_->~ObPLStmtBlock(); + else_ = NULL; } } @@ -2075,6 +2083,7 @@ public: virtual ~ObPLCaseStmt() { if (NULL != else_) { else_->~ObPLStmtBlock(); + else_ = NULL; } } @@ -2228,6 +2237,7 @@ public: virtual ~ObPLLoop() { if (NULL != body_) { body_->~ObPLStmtBlock(); + body_ = NULL; } } @@ -2796,6 +2806,7 @@ public: (const_cast(get_child_stmt(i)))->~ObPLStmt(); } } + handlers_.reset(); } int accept(ObPLStmtVisitor &visitor) const; diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index 92ce04b3a2..6dcc434aac 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -6929,6 +6929,7 @@ int ObSPIService::fill_cursor(ObResultSet &result_set, ObSPICursor *cursor) LOG_WARN("failed to copy pl extend", K(ret)); } else { obj = tmp; + cursor->complex_objs_.push_back(tmp); } } } diff --git a/src/sql/ob_spi.h b/src/sql/ob_spi.h index be98b087c8..3935f4897b 100644 --- a/src/sql/ob_spi.h +++ b/src/sql/ob_spi.h @@ -43,11 +43,19 @@ struct ObSPICursor ObSPICursor(ObIAllocator &allocator) : row_store_(), row_desc_(), allocator_(&allocator), cur_(0), fields_(allocator) {} + ~ObSPICursor() + { + for (int64_t i = 0; i < complex_objs_.count(); ++i) { + (void)(pl::ObUserDefinedType::destruct_obj(complex_objs_.at(i))); + } + } + ObRARowStore row_store_; ObArray row_desc_; //ObRowStore里数据自带的Meta可能是T_NULL,所以这里自备一份 ObIAllocator* allocator_; int64_t cur_; common::ColumnsFieldArray fields_; + ObArray complex_objs_; }; struct ObSPIOutParams