[fix](be-unit-test) Fix memory problems in agg_test.cpp. (#8019)

This commit is contained in:
Adonis Ling
2022-02-14 09:23:40 +08:00
committed by GitHub
parent 7d7e3a39f5
commit 18e2071278

View File

@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.
#include <memory>
#include <string>
#include "gtest/gtest.h"
@ -45,7 +46,8 @@ TEST(AggTest, basic_test) {
DataTypes data_types = {data_type};
Array array;
auto agg_function = factory.get("sum", data_types, array);
AggregateDataPtr place = new char[agg_function->size_of_data()];
std::unique_ptr<char[]> memory(new char[agg_function->size_of_data()]);
AggregateDataPtr place = memory.get();
agg_function->create(place);
const IColumn* column[1] = {column_vector_int32.get()};
for (int i = 0; i < agg_test_batch_size; i++) {
@ -55,11 +57,8 @@ TEST(AggTest, basic_test) {
for (int i = 0; i < agg_test_batch_size; i++) {
ans += i;
}
ASSERT_EQ(ans, *(int32_t*)place);
ASSERT_EQ(ans, *reinterpret_cast<int32_t*>(place));
agg_function->destroy(place);
if (place) {
free(place);
}
}
TEST(AggTest, topn_test) {
@ -80,7 +79,8 @@ TEST(AggTest, topn_test) {
Array array;
auto agg_function = factory.get("topn", data_types, array);
AggregateDataPtr place = new char[agg_function->size_of_data()];
std::unique_ptr<char[]> memory(new char[agg_function->size_of_data()]);
AggregateDataPtr place = memory.get();
agg_function->create(place);
IColumn* columns[2] = {datas[0].get(), datas[1].get()};