Skip to content

Commit

Permalink
Fix double-free when memtable agg
Browse files Browse the repository at this point in the history
  • Loading branch information
wangbo committed Jan 17, 2025
1 parent ba46b2d commit e35f17d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions be/src/olap/memtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ MemTable::MemTable(int64_t tablet_id, std::shared_ptr<TabletSchema> tablet_schem
g_memtable_cnt << 1;
_query_thread_context.init_unlocked();
_arena = std::make_unique<vectorized::Arena>();
_agg_func_arena = std::make_unique<vectorized::Arena>();
_vec_row_comparator = std::make_shared<RowInBlockComparator>(_tablet_schema);
_num_columns = _tablet_schema->num_columns();
if (partial_update_info != nullptr) {
Expand Down Expand Up @@ -160,6 +161,7 @@ MemTable::~MemTable() {
// Arena has to be destroyed after agg state, because some agg state's memory may be
// allocated in arena.
_arena.reset();
_agg_func_arena.reset();
_vec_row_comparator.reset();
_row_in_blocks.clear();
_agg_functions.clear();
Expand Down Expand Up @@ -390,7 +392,7 @@ void MemTable::_finalize_one_row(RowInBlock* row,
}
}

_arena->clear();
_agg_func_arena->clear();

if constexpr (is_final) {
row->remove_init_agg();
Expand All @@ -400,7 +402,7 @@ void MemTable::_finalize_one_row(RowInBlock* row,
auto* agg_place = row->agg_places(i);
auto* col_ptr = _output_mutable_block.get_column_by_position(i).get();
function->add(agg_place, const_cast<const doris::vectorized::IColumn**>(&col_ptr),
row_pos, _arena.get());
row_pos, _agg_func_arena.get());
}
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions be/src/olap/memtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ class MemTable {
// reduce the number of segment files that are generated by current load
std::unique_ptr<vectorized::Arena> _arena;

// used for _agg_functions.add
std::unique_ptr<vectorized::Arena> _agg_func_arena;

void _init_columns_offset_by_slot_descs(const std::vector<SlotDescriptor*>* slot_descs,
const TupleDescriptor* tuple_desc);
std::vector<int> _column_offset;
Expand Down

0 comments on commit e35f17d

Please sign in to comment.