From 57b63212a3ce154dbe98febb2924c9d9c869b55b Mon Sep 17 00:00:00 2001 From: trueeyu Date: Wed, 17 Apr 2024 18:52:24 +0800 Subject: [PATCH] Fix the mem leak of VectorizedFunctionCallExpr Signed-off-by: trueeyu --- be/src/exprs/function_call_expr.cpp | 4 ++-- be/test/exprs/function_call_expr_test.cpp | 27 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/be/src/exprs/function_call_expr.cpp b/be/src/exprs/function_call_expr.cpp index c6de1787d23901..bf6011e31e5206 100644 --- a/be/src/exprs/function_call_expr.cpp +++ b/be/src/exprs/function_call_expr.cpp @@ -134,8 +134,8 @@ Status VectorizedFunctionCallExpr::open(starrocks::RuntimeState* state, starrock void VectorizedFunctionCallExpr::close(starrocks::RuntimeState* state, starrocks::ExprContext* context, FunctionContext::FunctionStateScope scope) { - // _fn_context_index > 0 means this function call has call opened - if (_fn_desc != nullptr && _fn_desc->close_function != nullptr && _fn_context_index > 0) { + // _fn_context_index >= 0 means this function call has call opened + if (_fn_desc != nullptr && _fn_desc->close_function != nullptr && _fn_context_index >= 0) { FunctionContext* fn_ctx = context->fn_context(_fn_context_index); (void)_fn_desc->close_function(fn_ctx, FunctionContext::THREAD_LOCAL); diff --git a/be/test/exprs/function_call_expr_test.cpp b/be/test/exprs/function_call_expr_test.cpp index 9a19005b556b43..e539b21e5432be 100644 --- a/be/test/exprs/function_call_expr_test.cpp +++ b/be/test/exprs/function_call_expr_test.cpp @@ -280,4 +280,31 @@ TEST_F(VectorizedFunctionCallExprTest, prepareFaileCase) { exprContext.close(nullptr); } +TEST_F(VectorizedFunctionCallExprTest, prepare_close) { + TFunction func; + func.__set_fid(60010); // like + func.__set_binary_type(TFunctionBinaryType::BUILTIN); + + TExprNode expr_node; + expr_node.__set_fn(func); + expr_node.__set_opcode(TExprOpcode::ADD); + expr_node.__set_child_type(TPrimitiveType::INT); + expr_node.__set_node_type(TExprNodeType::BINARY_PRED); + expr_node.__set_num_children(2); + expr_node.__set_type(gen_type_desc(TPrimitiveType::BOOLEAN)); + + VectorizedFunctionCallExpr expr(expr_node); + ColumnRef col1(TypeDescriptor::create_varbinary_type(10), 1); + ColumnRef col2(TypeDescriptor::create_varbinary_type(10), 2); + expr.add_child(&col1); + expr.add_child(&col2); + + ExprContext expr_context(&expr); + Status st = expr_context.prepare(&_runtime_state); + ASSERT_TRUE(st.ok()); + st = expr_context.open(&_runtime_state); + ASSERT_TRUE(st.ok()); + expr_context.close(&_runtime_state); +} + } // namespace starrocks