From cd4fec8ab1bc74bd0b2b6d28aee1ef23fd05b835 Mon Sep 17 00:00:00 2001 From: HappenLee Date: Mon, 13 Jul 2020 20:52:22 +0800 Subject: [PATCH] [Bug] Fix core of double delete, when RowBatch call transfer_resource_ownership (#4052) Resource release should be done by dest RowBatch. When we call method transfer_resource_ownership. if we don't clear the corresponding resources, which will cause the core problem of double delete. --- be/src/runtime/row_batch.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/be/src/runtime/row_batch.cpp b/be/src/runtime/row_batch.cpp index a35b8f1841..4cfd953996 100644 --- a/be/src/runtime/row_batch.cpp +++ b/be/src/runtime/row_batch.cpp @@ -524,21 +524,28 @@ void RowBatch::transfer_resource_ownership(RowBatch* dest) { dest->_auxiliary_mem_usage += buffer->buffer_len(); buffer->set_mem_tracker(dest->_mem_tracker); } + _io_buffers.clear(); for (BufferInfo& buffer_info : _buffers) { dest->add_buffer( buffer_info.client, std::move(buffer_info.buffer), FlushMode::NO_FLUSH_RESOURCES); } + _buffers.clear(); for (int i = 0; i < _tuple_streams.size(); ++i) { dest->_tuple_streams.push_back(_tuple_streams[i]); dest->_auxiliary_mem_usage += _tuple_streams[i]->byte_size(); } + // Resource release should be done by dest RowBatch. if we don't clear the corresponding resources. + // This Rowbatch calls the reset() method, dest Rowbatch will also call the reset() method again, + // which will cause the core problem of double delete + _tuple_streams.clear(); for (int i = 0; i < _blocks.size(); ++i) { dest->_blocks.push_back(_blocks[i]); dest->_auxiliary_mem_usage += _blocks[i]->buffer_len(); } + _blocks.clear(); dest->_need_to_return |= _need_to_return;