From e22371ad034f3104e0aa3ba7c5f8e9cf6a8e9e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Fri, 12 Jan 2024 12:02:38 +0100 Subject: [PATCH 1/2] Fix double destroy call on exception throw in addBatchLookupTable8 --- src/Interpreters/Aggregator.cpp | 3 ++- .../0_stateless/02963_msan_agg_addBatchLookupTable8.reference | 0 .../0_stateless/02963_msan_agg_addBatchLookupTable8.sql | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02963_msan_agg_addBatchLookupTable8.reference create mode 100644 tests/queries/0_stateless/02963_msan_agg_addBatchLookupTable8.sql diff --git a/src/Interpreters/Aggregator.cpp b/src/Interpreters/Aggregator.cpp index cdc4292a79c..37f52f5b5be 100644 --- a/src/Interpreters/Aggregator.cpp +++ b/src/Interpreters/Aggregator.cpp @@ -1204,8 +1204,9 @@ void NO_INLINE Aggregator::executeImplBatch( inst->state_offset, [&](AggregateDataPtr & aggregate_data) { - aggregate_data = aggregates_pool->alignedAlloc(total_size_of_aggregate_states, align_aggregate_states); + AggregateDataPtr place = aggregates_pool->alignedAlloc(total_size_of_aggregate_states, align_aggregate_states); createAggregateStates(aggregate_data); + aggregate_data = place; }, state.getKeyData(), inst->batch_arguments, diff --git a/tests/queries/0_stateless/02963_msan_agg_addBatchLookupTable8.reference b/tests/queries/0_stateless/02963_msan_agg_addBatchLookupTable8.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/02963_msan_agg_addBatchLookupTable8.sql b/tests/queries/0_stateless/02963_msan_agg_addBatchLookupTable8.sql new file mode 100644 index 00000000000..a3a8bd0624a --- /dev/null +++ b/tests/queries/0_stateless/02963_msan_agg_addBatchLookupTable8.sql @@ -0,0 +1,2 @@ +-- https://github.com/ClickHouse/ClickHouse/issues/58727 +SELECT number % 2 AS even, aggThrow(number) FROM numbers(10) GROUP BY even; -- { serverError AGGREGATE_FUNCTION_THROW} From 78afc52564b09893d5f5f9762825dac17e55af20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Fri, 12 Jan 2024 12:28:03 +0100 Subject: [PATCH 2/2] Fix refactor --- src/Interpreters/Aggregator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interpreters/Aggregator.cpp b/src/Interpreters/Aggregator.cpp index 37f52f5b5be..967435db1b4 100644 --- a/src/Interpreters/Aggregator.cpp +++ b/src/Interpreters/Aggregator.cpp @@ -1205,7 +1205,7 @@ void NO_INLINE Aggregator::executeImplBatch( [&](AggregateDataPtr & aggregate_data) { AggregateDataPtr place = aggregates_pool->alignedAlloc(total_size_of_aggregate_states, align_aggregate_states); - createAggregateStates(aggregate_data); + createAggregateStates(place); aggregate_data = place; }, state.getKeyData(),