[CP] fix dynamic memleak when executing select stmt containing udf

This commit is contained in:
obdev
2022-12-07 07:06:00 +00:00
committed by ob-robot
parent 7d793b8862
commit 7ccc8ed5d3
3 changed files with 9 additions and 7 deletions

View File

@ -468,7 +468,8 @@ void ObPLContext::register_after_begin_autonomous_session_for_deadlock_(ObSQLSes
int ObPLContext::init(ObSQLSessionInfo &session_info, int ObPLContext::init(ObSQLSessionInfo &session_info,
ObExecContext &ctx, ObExecContext &ctx,
bool is_autonomous, bool is_autonomous,
bool is_function_or_trigger) bool is_function_or_trigger,
ObIAllocator *allocator)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
int64_t pl_block_timeout = 0; int64_t pl_block_timeout = 0;
@ -552,8 +553,7 @@ int ObPLContext::init(ObSQLSessionInfo &session_info,
} }
} }
OZ (ob_write_string( OZ (ob_write_string(allocator != NULL ? *allocator : ctx.get_allocator(), session_info.get_current_query_string(), cur_query_));
ctx.get_allocator(), session_info.get_current_query_string(), cur_query_));
OZ (recursion_ctx_.init(session_info)); OZ (recursion_ctx_.init(session_info));
OX (session_info.set_pl_stack_ctx(this)); OX (session_info.set_pl_stack_ctx(this));
@ -1500,7 +1500,8 @@ int ObPL::execute(ObExecContext &ctx,
routine->is_function() routine->is_function()
|| in_function || in_function
|| (package_id != OB_INVALID_ID || (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.inc_and_check_depth(package_id, routine_id, routine->is_function()));
OZ (stack_ctx.set_exec_env(*routine)); OZ (stack_ctx.set_exec_env(*routine));
OZ (stack_ctx.set_default_database(*routine, *(ctx.get_sql_ctx()->schema_guard_))); OZ (stack_ctx.set_default_database(*routine, *(ctx.get_sql_ctx()->schema_guard_)));

View File

@ -843,7 +843,7 @@ public:
int is_inited() { return session_info_ != NULL; } int is_inited() { return session_info_ != NULL; }
int init(sql::ObSQLSessionInfo &session_info, sql::ObExecContext &ctx, 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); void destory(sql::ObSQLSessionInfo &session_info, sql::ObExecContext &ctx, int &ret);
inline ObPLCursorInfo& get_cursor_info() { return cursor_info_; } inline ObPLCursorInfo& get_cursor_info() { return cursor_info_; }

View File

@ -480,13 +480,14 @@ int ObExprUDF::eval_udf(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
CK (0 < udf_params->count()); CK (0 < udf_params->count());
OZ (ns.init_complex_obj(alloc, pl_type, udf_params->at(0), false, false)); OZ (ns.init_complex_obj(alloc, pl_type, udf_params->at(0), false, false));
} }
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
ObArenaAllocator allocator;
try { try {
int64_t package_id = info->is_udt_udf_ ? int64_t package_id = info->is_udt_udf_ ?
share::schema::ObUDTObjectType::mask_object_id(info->udf_package_id_) share::schema::ObUDTObjectType::mask_object_id(info->udf_package_id_)
: info->udf_package_id_; : info->udf_package_id_;
OZ(pl_engine->execute(ctx.exec_ctx_, OZ(pl_engine->execute(ctx.exec_ctx_,
info->is_called_in_sql_ ? tmp_alloc_g.get_allocator() info->is_called_in_sql_ ? allocator
: alloc, : alloc,
package_id, package_id,
info->udf_id_, info->udf_id_,