[CP] to issue<52735354>:fix dynamic memory leak

This commit is contained in:
obdev
2024-02-06 17:29:16 +00:00
committed by ob-robot
parent 85e87077a2
commit 163593a32c
3 changed files with 52 additions and 15 deletions

View File

@ -49,6 +49,7 @@
#endif
#include "pl/pl_cache/ob_pl_cache_mgr.h"
#include "sql/engine/dml/ob_trigger_handler.h"
#include "pl/ob_pl_allocator.h"
namespace oceanbase
{
using namespace common;
@ -1560,7 +1561,9 @@ int ObPL::trans_sql(PlTransformTreeCtx &trans_ctx, ParseNode *root, ObExecContex
}
CK (OB_NOT_NULL(trans_ctx.params_));
for (int64_t i = 0; OB_SUCC(ret) && i < params.count(); ++i) {
OZ (trans_ctx.params_->push_back(params.at(i)));
ObObjParam obj = params.at(i);
OZ (deep_copy_obj(ctx.get_allocator(), params.at(i), obj));
OZ (trans_ctx.params_->push_back(obj));
}
}
}
@ -1636,13 +1639,14 @@ int ObPL::parameter_anonymous_block(ObExecContext &ctx,
ObCacheObjGuard &cacheobj_guard)
{
int ret = OB_SUCCESS;
ObString pc_key;
CK (OB_NOT_NULL(ctx.get_my_session()));
CK (OB_NOT_NULL(block));
if (OB_SUCC(ret)) {
ObArenaAllocator paramerter_alloc("AnonyParam", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObString sql(static_cast<int64_t>(block->str_len_), block->str_value_);
ObString pc_key;
ParseResult parse_result;
ObPLParser pl_parser(allocator,
ObPLParser pl_parser(paramerter_alloc,
ctx.get_my_session()->get_charsets4parser(),
ctx.get_my_session()->get_sql_mode());
OZ (pl_parser.fast_parse(sql, parse_result));
@ -1650,7 +1654,7 @@ int ObPL::parameter_anonymous_block(ObExecContext &ctx,
PlTransformTreeCtx trans_ctx;
ParseNode *block_node = NULL;
memset(&trans_ctx, 0, sizeof(PlTransformTreeCtx));
trans_ctx.allocator_ = &allocator;
trans_ctx.allocator_ = &paramerter_alloc;
trans_ctx.raw_sql_ = sql;
trans_ctx.raw_anonymous_off_ = block->pl_str_off_;
trans_ctx.params_ = &params;
@ -1679,11 +1683,12 @@ int ObPL::parameter_anonymous_block(ObExecContext &ctx,
trans_ctx.buf_len_ += trans_ctx.raw_sql_.length() - trans_ctx.copied_idx_;
}
}
pc_key.assign_ptr(trans_ctx.buf_, trans_ctx.buf_len_);
//pc_key.assign_ptr(trans_ctx.buf_, trans_ctx.buf_len_);
OZ (ob_write_string(ctx.get_allocator(), ObString(trans_ctx.buf_len_, trans_ctx.buf_), pc_key));
}
}
}
OZ (get_pl_function(ctx, params, OB_INVALID_ID, pc_key, cacheobj_guard));
}
}
}
return ret;
}

View File

@ -10,6 +10,20 @@
* See the Mulan PubL v2 for more details.
*/
#ifdef PL_MOD_DEF
PL_MOD_DEF(OB_PL_ANONY_PARAMETER, "AnonyParam")
PL_MOD_DEF(OB_PL_SET_VAR, "SetVar")
PL_MOD_DEF(OB_PL_STATIC_SQL_EXEC, "StaticExec")
PL_MOD_DEF(OB_PL_DYNAMIC_SQL_EXEC, "DyncmicExec")
PL_MOD_DEF(OB_PL_BULK_INTO, "BulkInto")
PL_MOD_DEF(OB_PL_UDT, "Udt")
PL_MOD_DEF(OB_PL_DEBUG_MOD, "PlDebug")
PL_MOD_DEF(OB_PL_DEBUG_SYS_MOD, "PlDebugSys")
PL_MOD_DEF(OB_PL_ANY_DATA, "AnyData")
PL_MOD_DEF(OB_PL_ANY_TYPE, "AnyType")
#endif
#ifndef OCEANBASE_SRC_PL_OB_PL_ALLOCATOR_H_
#define OCEANBASE_SRC_PL_OB_PL_ALLOCATOR_H_
@ -112,6 +126,24 @@ private:
ObPLPackageState *state_;
};
enum PL_MOD_IDX {
OB_MOD_INVALID = -1,
#define PL_MOD_DEF(type, name) type,
#include "pl/ob_pl_allocator.h"
#undef PL_MOD_DEF
PL_MOD_IDX_NUM
};
static constexpr const char* OB_PL_MOD_DEF[PL_MOD_IDX_NUM] =
{
#define PL_MOD_DEF(type, name) name,
#include "pl/ob_pl_allocator.h"
#undef PL_MOD_DEF
};
#define GET_PL_MOD_STRING(type) (type > OB_MOD_INVALID && type < PL_MOD_IDX_NUM) ? OB_PL_MOD_DEF[type] : "PlTemp"
}
}

View File

@ -42,7 +42,7 @@
#ifdef OB_BUILD_ORACLE_PL
#include "pl/dblink/ob_pl_dblink_util.h"
#endif
#include "pl/ob_pl_allocator.h"
namespace oceanbase
{
using namespace sqlclient;
@ -233,7 +233,7 @@ int ObSPIResultSet::is_set_global_var(ObSQLSessionInfo &session, const ObString
{
int ret = OB_SUCCESS;
has_global_variable = false;
ObArenaAllocator allocator;
ObArenaAllocator allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_SET_VAR), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ParseResult parse_result;
ParseMode parse_mode = STD_MODE;
ObParser parser(allocator, session.get_sql_mode(), session.get_charsets4parser());
@ -1250,7 +1250,7 @@ int ObSPIService::set_variable(ObPLExecCtx *ctx,
LOG_WARN("Argument passed in is NULL", K(ctx), K(name), K(value), K(ret));
} else {
ObSQLSessionInfo *session = ctx->exec_ctx_->get_my_session();
ObArenaAllocator allocator;
ObArenaAllocator allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_SET_VAR), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("Argument in pl context is NULL", K(session), K(ret));
@ -1588,7 +1588,7 @@ int ObSPIService::spi_inner_execute(ObPLExecCtx *ctx,
// SQL_AUDIT_START
ObWaitEventDesc max_wait_desc;
ObWaitEventStat total_wait_desc;
ObArenaAllocator allocator;
ObArenaAllocator allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_STATIC_SQL_EXEC), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
const bool enable_perf_event = lib::is_diagnose_info_enabled();
const bool enable_sql_audit =
GCONF.enable_sql_audit && ctx->exec_ctx_->get_my_session()->get_local_ob_enable_sql_audit();
@ -2399,7 +2399,7 @@ int ObSPIService::calc_dynamic_sqlstr(
LOG_WARN("Dynamic sql is not a string", K(ret), K(result), K(sql_str));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Dynamic sql is not a string");
} else {
ObArenaAllocator temp_allocator;
ObArenaAllocator temp_allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_DYNAMIC_SQL_EXEC), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObString tmp_sql;
ObString user_sql;
ObCharsetType client_cs_type = CHARSET_INVALID;
@ -2622,7 +2622,7 @@ int ObSPIService::spi_execute_immediate(ObPLExecCtx *ctx,
ObSQLSessionInfo *session = NULL;
ObMySQLProxy *sql_proxy = NULL;
ObSqlString sql_str;
ObArenaAllocator allocator;
ObArenaAllocator allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_DYNAMIC_SQL_EXEC), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
HEAP_VAR(ObSPIResultSet, spi_result) {
stmt::StmtType stmt_type = stmt::T_NONE;
ObString ps_sql;
@ -2758,7 +2758,7 @@ int ObSPIService::spi_execute_immediate(ObPLExecCtx *ctx,
session->set_query_start_time(ObTimeUtility::current_time());
bool is_retry = false;
do {
ObArenaAllocator allocator;
ObArenaAllocator allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_DYNAMIC_SQL_EXEC), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ParamStore exec_params( (ObWrapperAllocator(allocator)) );
ObWaitEventDesc max_wait_desc;
ObWaitEventStat total_wait_desc;
@ -3340,7 +3340,7 @@ int ObSPIService::spi_dynamic_open(ObPLExecCtx *ctx,
int ret = OB_SUCCESS;
ObSqlString sql_str;
stmt::StmtType stmt_type = stmt::T_NONE;
ObArenaAllocator allocator;
ObArenaAllocator allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_DYNAMIC_SQL_EXEC), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObString ps_sql;
bool for_update = false;
bool hidden_rowid = false;
@ -6968,7 +6968,7 @@ int ObSPIService::get_result(ObPLExecCtx *ctx,
ObArray<ObPLCollection*> bulk_tables;
ObArray<ObCastCtx> cast_ctxs;
ObArray<std::pair<uint64_t, uint64_t>> package_vars_info;
ObArenaAllocator tmp_allocator;
ObArenaAllocator tmp_allocator(GET_PL_MOD_STRING(PL_MOD_IDX::OB_PL_BULK_INTO), OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
OZ (bulk_tables.reserve(OB_DEFAULT_SE_ARRAY_COUNT));
OZ (cast_ctxs.reserve(OB_DEFAULT_SE_ARRAY_COUNT));
OZ (package_vars_info.reserve(OB_DEFAULT_SE_ARRAY_COUNT));