diff --git a/be/src/vec/exec/vaggregation_node.h b/be/src/vec/exec/vaggregation_node.h index fba82aa8c9..30eb8aa9d3 100644 --- a/be/src/vec/exec/vaggregation_node.h +++ b/be/src/vec/exec/vaggregation_node.h @@ -326,12 +326,26 @@ public: private: void _expand() { _index_in_sub_container = 0; - _current_keys = _arena_pool.alloc(_size_of_key * SUB_CONTAINER_CAPACITY); - _key_containers.emplace_back(_current_keys); + _current_keys = nullptr; + _current_agg_data = nullptr; + try { + _current_keys = _arena_pool.alloc(_size_of_key * SUB_CONTAINER_CAPACITY); + _key_containers.emplace_back(_current_keys); - _current_agg_data = (AggregateDataPtr)_arena_pool.alloc(_size_of_aggregate_states * - SUB_CONTAINER_CAPACITY); - _value_containers.emplace_back(_current_agg_data); + _current_agg_data = (AggregateDataPtr)_arena_pool.alloc(_size_of_aggregate_states * + SUB_CONTAINER_CAPACITY); + _value_containers.emplace_back(_current_agg_data); + } catch (...) { + if (_current_keys) { + _key_containers.pop_back(); + _current_keys = nullptr; + } + if (_current_agg_data) { + _value_containers.pop_back(); + _current_agg_data = nullptr; + } + throw; + } } static constexpr uint32_t SUB_CONTAINER_CAPACITY = 8192;