Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](coalesce) fix 'heap-use-after-free' of function coalesce (#42666) #42667

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions be/src/vec/functions/function_coalesce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class FunctionCoalesce : public IFunction {
public:
static constexpr auto name = "coalesce";

mutable DataTypePtr result_type;
mutable FunctionBasePtr func_is_not_null;

static FunctionPtr create() { return std::make_shared<FunctionCoalesce>(); }
Expand All @@ -70,26 +69,25 @@ class FunctionCoalesce : public IFunction {
size_t get_number_of_arguments() const override { return 0; }

DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
DataTypePtr res;
for (const auto& arg : arguments) {
if (!arg->is_nullable()) {
result_type = arg;
res = arg;
break;
}
}

result_type = result_type ? result_type : arguments[0];
return result_type;
res = res ? res : arguments[0];

const ColumnsWithTypeAndName is_not_null_col {{nullptr, make_nullable(res), ""}};
func_is_not_null = SimpleFunctionFactory::instance().get_function(
"is_not_null_pred", is_not_null_col, std::make_shared<DataTypeUInt8>());

return res;
}

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
size_t result, size_t input_rows_count) const override {
if (!func_is_not_null) [[unlikely]] {
const ColumnsWithTypeAndName is_not_null_col {
{nullptr, make_nullable(result_type), ""}};
func_is_not_null = SimpleFunctionFactory::instance().get_function(
"is_not_null_pred", is_not_null_col, std::make_shared<DataTypeUInt8>(),
{.enable_decimal256 = context->state()->enable_decimal256()});
}
DCHECK_GE(arguments.size(), 1);
DataTypePtr result_type = block.get_by_position(result).type;
ColumnNumbers filtered_args;
Expand Down
Loading