From c7a7805e274fa4eb71570a65757cbe43f0cfc85c Mon Sep 17 00:00:00 2001 From: JinmaoLi Date: Fri, 24 May 2024 12:02:07 +0000 Subject: [PATCH] fix memory leak caused by ObSolidifiedVarsContext::local_tz_wrap_ --- src/sql/engine/expr/ob_expr_util.cpp | 27 ------------------------- src/sql/engine/expr/ob_expr_util.h | 5 +++-- src/sql/engine/ob_exec_context.cpp | 2 +- src/sql/engine/ob_physical_plan_ctx.cpp | 2 +- src/sql/engine/ob_physical_plan_ctx.h | 7 +++++++ 5 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/sql/engine/expr/ob_expr_util.cpp b/src/sql/engine/expr/ob_expr_util.cpp index 9e4ddeef27..1872c5bf66 100644 --- a/src/sql/engine/expr/ob_expr_util.cpp +++ b/src/sql/engine/expr/ob_expr_util.cpp @@ -766,33 +766,6 @@ int ObSolidifiedVarsContext::get_local_tz_info(const sql::ObBasicSessionInfo *se return ret; } -OB_DEF_SERIALIZE(ObSolidifiedVarsContext) -{ - int ret = OB_SUCCESS; - if (NULL != local_session_var_) { - OB_UNIS_ENCODE(*local_session_var_); - } - return ret; -} - -OB_DEF_SERIALIZE_SIZE(ObSolidifiedVarsContext) -{ - int64_t len = 0; - if (NULL != local_session_var_) { - OB_UNIS_ADD_LEN(*local_session_var_); - } - return len; -} - -OB_DEF_DESERIALIZE(ObSolidifiedVarsContext) -{ - int ret = OB_SUCCESS; - if (NULL != local_session_var_) { - OB_UNIS_DECODE(*local_session_var_); - } - return ret; -} - DEF_TO_STRING(ObSolidifiedVarsContext) { int64_t pos = 0; diff --git a/src/sql/engine/expr/ob_expr_util.h b/src/sql/engine/expr/ob_expr_util.h index e9dfa98e98..296686001a 100644 --- a/src/sql/engine/expr/ob_expr_util.h +++ b/src/sql/engine/expr/ob_expr_util.h @@ -228,7 +228,6 @@ int calc_##tritype##_expr(const ObExpr &expr, ObEvalCtx &ctx, \ class ObSolidifiedVarsContext { - OB_UNIS_VERSION(1); public: ObSolidifiedVarsContext() : local_session_var_(NULL), @@ -242,8 +241,10 @@ public: local_tz_wrap_(NULL) { } - virtual ~ObSolidifiedVarsContext() { + virtual ~ObSolidifiedVarsContext() + { if (NULL != local_tz_wrap_ && NULL != alloc_) { + local_tz_wrap_->~ObTimeZoneInfoWrap(); alloc_->free(local_tz_wrap_); local_tz_wrap_ = NULL; } diff --git a/src/sql/engine/ob_exec_context.cpp b/src/sql/engine/ob_exec_context.cpp index e32013fae2..8098537a1a 100644 --- a/src/sql/engine/ob_exec_context.cpp +++ b/src/sql/engine/ob_exec_context.cpp @@ -146,7 +146,7 @@ ObExecContext::~ObExecContext() phy_plan_ctx_->~ObPhysicalPlanCtx(); } else { // free subschema map memory - phy_plan_ctx_->get_subschema_ctx().destroy(); + phy_plan_ctx_->destroy(); } } phy_plan_ctx_ = NULL; diff --git a/src/sql/engine/ob_physical_plan_ctx.cpp b/src/sql/engine/ob_physical_plan_ctx.cpp index 038db5c99f..3b7118966d 100644 --- a/src/sql/engine/ob_physical_plan_ctx.cpp +++ b/src/sql/engine/ob_physical_plan_ctx.cpp @@ -129,7 +129,7 @@ ObPhysicalPlanCtx::ObPhysicalPlanCtx(common::ObIAllocator &allocator) ObPhysicalPlanCtx::~ObPhysicalPlanCtx() { - subschema_ctx_.destroy(); + destroy(); } void ObPhysicalPlanCtx::restore_param_store(const int64_t original_param_cnt) diff --git a/src/sql/engine/ob_physical_plan_ctx.h b/src/sql/engine/ob_physical_plan_ctx.h index 08de915dbb..4eb630a458 100644 --- a/src/sql/engine/ob_physical_plan_ctx.h +++ b/src/sql/engine/ob_physical_plan_ctx.h @@ -97,6 +97,13 @@ class ObPhysicalPlanCtx public: explicit ObPhysicalPlanCtx(common::ObIAllocator &allocator); virtual ~ObPhysicalPlanCtx(); + void destroy() + { + // Member variables that need to request additional memory + // with another allocator should call destroy here. + subschema_ctx_.destroy(); + all_local_session_vars_.destroy(); + } inline void set_tenant_id(uint64_t tenant_id) { tenant_id_ = tenant_id; } inline void set_show_seed(bool show_seed) { is_show_seed_ = show_seed; } inline uint64_t get_tenant_id() { return tenant_id_; }