issue<48107888>:fix memory leak of inner store routine with out argument

This commit is contained in:
obdev 2023-04-19 07:11:50 +00:00 committed by ob-robot
parent 05d068d8ee
commit 0d6dc4e2ca
5 changed files with 44 additions and 0 deletions

View File

@ -104,6 +104,8 @@ int ObPL::init(common::ObMySQLProxy &sql_proxy)
(void*)(sql::ObSPIService::spi_reset_collection));
jit::ObLLVMHelper::add_symbol(ObString("spi_copy_datum"),
(void*)(sql::ObSPIService::spi_copy_datum));
jit::ObLLVMHelper::add_symbol(ObString("spi_destruct_obj"),
(void*)(sql::ObSPIService::spi_destruct_obj));
jit::ObLLVMHelper::add_symbol(ObString("spi_sub_nestedtable"),
(void*)(sql::ObSPIService::spi_sub_nestedtable));
jit::ObLLVMHelper::add_symbol(ObString("spi_alloc_complex_var"),

View File

@ -3743,6 +3743,13 @@ int ObPLCodeGenerator::init_spi_service()
OZ (ObLLVMFunctionType::get(int32_type, arg_types, ft));
OZ (helper_.create_function(ObString("spi_copy_datum"), ft, spi_service_.spi_copy_datum_));
}
if (OB_SUCC(ret)) {
arg_types.reset();
OZ (arg_types.push_back(pl_exec_context_pointer_type)); //函数第一个参数必须是基础环境信息隐藏参数
OZ (arg_types.push_back(obj_pointer_type)); //src
OZ (ObLLVMFunctionType::get(int32_type, arg_types, ft));
OZ (helper_.create_function(ObString("spi_destruct_obj"), ft, spi_service_.spi_destruct_obj_));
}
if (OB_SUCC(ret)) {
arg_types.reset();
@ -7648,6 +7655,20 @@ int ObPLCodeGenerator::generate_out_param(
s.get_block()->in_notfound(),
s.get_block()->in_warning(),
OB_INVALID_ID));
if (OB_SUCC(ret) && PL_CALL == s.get_type()) {
ObSEArray<jit::ObLLVMValue, 2> args;
OZ (args.push_back(get_vars()[CTX_IDX]));
OZ (args.push_back(src_datum));
if (OB_SUCC(ret)) {
jit::ObLLVMValue ret_err;
if (OB_FAIL(get_helper().create_call(ObString("spi_destruct_obj"), get_spi_service().spi_destruct_obj_, args, ret_err))) {
LOG_WARN("failed to create call", K(ret));
} else if (OB_FAIL(check_success(ret_err, s.get_stmt_id(), s.get_block()->in_notfound(), s.get_block()->in_warning()))) {
LOG_WARN("failed to check success", K(ret));
} else { /*do nothing*/ }
}
}
}
} else { //处理基础类型的出参
ObSEArray<ObLLVMValue, 4> args;

View File

@ -77,6 +77,7 @@ public:
jit::ObLLVMFunction spi_init_collection_;
jit::ObLLVMFunction spi_reset_collection_;
jit::ObLLVMFunction spi_copy_datum_;
jit::ObLLVMFunction spi_destruct_obj_;
jit::ObLLVMFunction spi_sub_nestedtable_;
jit::ObLLVMFunction spi_alloc_complex_var_;
jit::ObLLVMFunction spi_construct_collection_;

View File

@ -4806,6 +4806,23 @@ int ObSPIService::spi_copy_datum(ObPLExecCtx *ctx,
return ret;
}
int ObSPIService::spi_destruct_obj(ObPLExecCtx *ctx,
ObObj *obj)
{
int ret = OB_SUCCESS;
CK (OB_NOT_NULL(ctx));
CK (OB_NOT_NULL(ctx->exec_ctx_));
CK (OB_NOT_NULL(obj));
if (OB_SUCC(ret) &&
obj->is_pl_extend() &&
obj->get_meta().get_extend_type() != pl::PL_REF_CURSOR_TYPE) {
OZ (ObUserDefinedType::destruct_obj(*obj, ctx->exec_ctx_->get_my_session()));
}
SET_SPI_STATUS;
return ret;
}
int ObSPIService::spi_interface_impl(pl::ObPLExecCtx* ctx, int64_t func_addr)
{
int ret = OB_SUCCESS;

View File

@ -549,6 +549,9 @@ public:
ObDataType *dest_type,
uint64_t package_id = OB_INVALID_ID);
static int spi_destruct_obj(pl::ObPLExecCtx *ctx,
ObObj *obj);
static int spi_build_record_type(common::ObIAllocator &allocator,
ObSQLSessionInfo &session,
share::schema::ObSchemaGetterGuard &schema_guard,