From 57568ba472049469a2ba6cdee83e70bf661f74ec Mon Sep 17 00:00:00 2001 From: starocean999 <40539150+starocean999@users.noreply.github.com> Date: Thu, 17 Aug 2023 22:18:09 +0800 Subject: [PATCH] [fix](be)shouldn't use arena to alloc memory for SingleValueDataString (#23075) * [fix](be)shouldn't use arena to alloc memory for SingleValueDataString * format code --- .../aggregate_function_min_max.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_min_max.h b/be/src/vec/aggregate_functions/aggregate_function_min_max.h index 778d311214..dcc58204f8 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_min_max.h +++ b/be/src/vec/aggregate_functions/aggregate_function_min_max.h @@ -297,7 +297,7 @@ private: Int32 size = -1; /// -1 indicates that there is no value. Int32 capacity = 0; /// power of two or zero - char* large_data = nullptr; + std::unique_ptr large_data; public: static constexpr Int32 AUTOMATIC_STORAGE_SIZE = 64; @@ -314,7 +314,9 @@ public: bool has() const { return size >= 0; } - const char* get_data() const { return size <= MAX_SMALL_STRING_SIZE ? small_data : large_data; } + const char* get_data() const { + return size <= MAX_SMALL_STRING_SIZE ? small_data : large_data.get(); + } void insert_result_into(IColumn& to) const { if (has()) { @@ -328,7 +330,6 @@ public: if (size != -1) { size = -1; capacity = 0; - delete[] large_data; large_data = nullptr; } } @@ -356,11 +357,11 @@ public: } else { if (capacity < rhs_size) { capacity = round_up_to_power_of_two_or_zero(rhs_size); - large_data = arena->alloc(capacity); + large_data.reset(new char[capacity]); } size = rhs_size; - buf.read(large_data, size); + buf.read(large_data.get(), size); } } else { /// Don't free large_data here. @@ -385,11 +386,11 @@ public: if (capacity < value_size) { /// Don't free large_data here. capacity = round_up_to_power_of_two_or_zero(value_size); - large_data = arena->alloc(capacity); + large_data.reset(new char[capacity]); } size = value_size; - memcpy(large_data, value.data, size); + memcpy(large_data.get(), value.data, size); } }