Skip to content

Commit

Permalink
[BugFix] Fix the mem leak of VectorizedFunctionCallExpr (backport #44275
Browse files Browse the repository at this point in the history
) (#44364)

Co-authored-by: trueeyu <[email protected]>
  • Loading branch information
mergify[bot] and trueeyu authored Apr 18, 2024
1 parent 49a3642 commit a947b18
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions be/src/exprs/function_call_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,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);
_fn_desc->close_function(fn_ctx, FunctionContext::THREAD_LOCAL);

Expand Down
27 changes: 27 additions & 0 deletions be/test/exprs/function_call_expr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a947b18

Please sign in to comment.