Skip to content

Commit

Permalink
[fix](partial update) fix a mem leak issue (apache#37706)
Browse files Browse the repository at this point in the history
we should avoid to use raw pointer
  • Loading branch information
zhannngchen committed Jul 12, 2024
1 parent d085c5e commit 84fa70f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions be/src/olap/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3113,23 +3113,21 @@ void Tablet::sort_block(vectorized::Block& in_block, vectorized::Block& output_b
vectorized::MutableBlock mutable_output_block =
vectorized::MutableBlock::build_mutable_block(&output_block);

std::vector<RowInBlock*> _row_in_blocks;
_row_in_blocks.reserve(in_block.rows());

std::unique_ptr<Schema> schema(new Schema(_schema));
std::shared_ptr<RowInBlockComparator> vec_row_comparator =
std::make_shared<RowInBlockComparator>(schema.get());
vec_row_comparator->set_block(&mutable_input_block);

std::vector<RowInBlock*> row_in_blocks;
std::vector<std::unique_ptr<RowInBlock>> row_in_blocks;
DCHECK(in_block.rows() <= std::numeric_limits<int>::max());
row_in_blocks.reserve(in_block.rows());
for (size_t i = 0; i < in_block.rows(); ++i) {
row_in_blocks.emplace_back(new RowInBlock {i});
row_in_blocks.emplace_back(std::make_unique<RowInBlock>(i));
}
std::sort(row_in_blocks.begin(), row_in_blocks.end(),
[&](const RowInBlock* l, const RowInBlock* r) -> bool {
auto value = (*vec_row_comparator)(l, r);
[&](const std::unique_ptr<RowInBlock>& l,
const std::unique_ptr<RowInBlock>& r) -> bool {
auto value = (*vec_row_comparator)(l.get(), r.get());
DCHECK(value != 0) << "value equel when sort block, l_pos: " << l->_row_pos
<< " r_pos: " << r->_row_pos;
return value < 0;
Expand Down

0 comments on commit 84fa70f

Please sign in to comment.