From 7ccc8ed5d303bdb628ffbf8b033f5af734f672ec Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 7 Dec 2022 07:06:00 +0000 Subject: [PATCH] [CP] fix dynamic memleak when executing select stmt containing udf --- src/pl/ob_pl.cpp | 9 +++++---- src/pl/ob_pl.h | 2 +- src/sql/engine/expr/ob_expr_udf.cpp | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pl/ob_pl.cpp b/src/pl/ob_pl.cpp index af4a78fa00..ad44e4d2df 100644 --- a/src/pl/ob_pl.cpp +++ b/src/pl/ob_pl.cpp @@ -468,7 +468,8 @@ void ObPLContext::register_after_begin_autonomous_session_for_deadlock_(ObSQLSes int ObPLContext::init(ObSQLSessionInfo &session_info, ObExecContext &ctx, bool is_autonomous, - bool is_function_or_trigger) + bool is_function_or_trigger, + ObIAllocator *allocator) { int ret = OB_SUCCESS; int64_t pl_block_timeout = 0; @@ -552,8 +553,7 @@ int ObPLContext::init(ObSQLSessionInfo &session_info, } } - OZ (ob_write_string( - ctx.get_allocator(), session_info.get_current_query_string(), cur_query_)); + OZ (ob_write_string(allocator != NULL ? *allocator : ctx.get_allocator(), session_info.get_current_query_string(), cur_query_)); OZ (recursion_ctx_.init(session_info)); OX (session_info.set_pl_stack_ctx(this)); @@ -1500,7 +1500,8 @@ int ObPL::execute(ObExecContext &ctx, routine->is_function() || in_function || (package_id != OB_INVALID_ID - && ObTriggerInfo::is_trigger_package_id(package_id)))); + && ObTriggerInfo::is_trigger_package_id(package_id)), + &allocator)); OZ (stack_ctx.inc_and_check_depth(package_id, routine_id, routine->is_function())); OZ (stack_ctx.set_exec_env(*routine)); OZ (stack_ctx.set_default_database(*routine, *(ctx.get_sql_ctx()->schema_guard_))); diff --git a/src/pl/ob_pl.h b/src/pl/ob_pl.h index fa3eca228e..28922c461a 100644 --- a/src/pl/ob_pl.h +++ b/src/pl/ob_pl.h @@ -843,7 +843,7 @@ public: int is_inited() { return session_info_ != NULL; } int init(sql::ObSQLSessionInfo &session_info, sql::ObExecContext &ctx, - bool is_autonomous, bool is_function_or_trigger); + bool is_autonomous, bool is_function_or_trigger, ObIAllocator *allocator = NULL); void destory(sql::ObSQLSessionInfo &session_info, sql::ObExecContext &ctx, int &ret); inline ObPLCursorInfo& get_cursor_info() { return cursor_info_; } diff --git a/src/sql/engine/expr/ob_expr_udf.cpp b/src/sql/engine/expr/ob_expr_udf.cpp index 4398935303..3619f15ff0 100644 --- a/src/sql/engine/expr/ob_expr_udf.cpp +++ b/src/sql/engine/expr/ob_expr_udf.cpp @@ -480,13 +480,14 @@ int ObExprUDF::eval_udf(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res) CK (0 < udf_params->count()); OZ (ns.init_complex_obj(alloc, pl_type, udf_params->at(0), false, false)); } - ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx); + + ObArenaAllocator allocator; try { int64_t package_id = info->is_udt_udf_ ? share::schema::ObUDTObjectType::mask_object_id(info->udf_package_id_) : info->udf_package_id_; OZ(pl_engine->execute(ctx.exec_ctx_, - info->is_called_in_sql_ ? tmp_alloc_g.get_allocator() + info->is_called_in_sql_ ? allocator : alloc, package_id, info->udf_id_,