diff --git a/be/src/vec/exec/vaggregation_node.cpp b/be/src/vec/exec/vaggregation_node.cpp index 67924a61b639b6..eff5db74832f79 100644 --- a/be/src/vec/exec/vaggregation_node.cpp +++ b/be/src/vec/exec/vaggregation_node.cpp @@ -822,18 +822,25 @@ void AggregationNode::_emplace_into_hash_table(AggregateDataPtr* places, ColumnR auto creator = [this](const auto& ctor, const auto& key) { using KeyType = std::decay_t; - if constexpr (HashTableTraits::is_string_hash_table && - !std::is_same_v) { - StringRef string_ref = to_string_ref(key); - ArenaKeyHolder key_holder {string_ref, *_agg_arena_pool}; - key_holder_persist_key(key_holder); - auto mapped = _aggregate_data_container->append_data(key_holder.key); - _create_agg_status(mapped); - ctor(key, mapped); - } else { - auto mapped = _aggregate_data_container->append_data(key); - _create_agg_status(mapped); - ctor(key, mapped); + try { + if constexpr (HashTableTraits::is_string_hash_table && + !std::is_same_v) { + StringRef string_ref = to_string_ref(key); + ArenaKeyHolder key_holder {string_ref, *_agg_arena_pool}; + key_holder_persist_key(key_holder); + auto mapped = _aggregate_data_container->append_data(key_holder.key); + _create_agg_status(mapped); + ctor(key, mapped); + } else { + auto mapped = _aggregate_data_container->append_data(key); + _create_agg_status(mapped); + ctor(key, mapped); + } + } catch (...) { + // Exception-safety - if it can not allocate memory or create status, + // the destructors will not be called. + ctor(key, nullptr); + throw; } };