From 37de54937cede70f5b7ce4fd6eb8a65c6c6691af Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Sun, 24 Oct 2021 22:32:28 +0300 Subject: [PATCH] fix use-after-free --- src/Interpreters/AsynchronousInsertQueue.cpp | 10 ++++++++-- ...ert_7.reference => 02015_async_inserts_7.reference} | 0 ...2015_async_insert_7.sh => 02015_async_inserts_7.sh} | 0 3 files changed, 8 insertions(+), 2 deletions(-) rename tests/queries/0_stateless/{02015_async_insert_7.reference => 02015_async_inserts_7.reference} (100%) rename tests/queries/0_stateless/{02015_async_insert_7.sh => 02015_async_inserts_7.sh} (100%) diff --git a/src/Interpreters/AsynchronousInsertQueue.cpp b/src/Interpreters/AsynchronousInsertQueue.cpp index cc04c5f013f..2f86c8bef28 100644 --- a/src/Interpreters/AsynchronousInsertQueue.cpp +++ b/src/Interpreters/AsynchronousInsertQueue.cpp @@ -407,14 +407,20 @@ try } StreamingFormatExecutor executor(header, format, std::move(on_error), std::move(adding_defaults_transform)); - std::unique_ptr buffer; + std::unique_ptr last_buffer; for (const auto & entry : data->entries) { - buffer = std::make_unique(entry->bytes); + auto buffer = std::make_unique(entry->bytes); current_entry = entry; total_rows += executor.execute(*buffer); + + /// Keep buffer, because it still can be used + /// in destructor, while resetting buffer at next iteration. + last_buffer = std::move(buffer); } + format->addBuffer(std::move(last_buffer)); + auto chunk = Chunk(executor.getResultColumns(), total_rows); size_t total_bytes = chunk.bytes(); diff --git a/tests/queries/0_stateless/02015_async_insert_7.reference b/tests/queries/0_stateless/02015_async_inserts_7.reference similarity index 100% rename from tests/queries/0_stateless/02015_async_insert_7.reference rename to tests/queries/0_stateless/02015_async_inserts_7.reference diff --git a/tests/queries/0_stateless/02015_async_insert_7.sh b/tests/queries/0_stateless/02015_async_inserts_7.sh similarity index 100% rename from tests/queries/0_stateless/02015_async_insert_7.sh rename to tests/queries/0_stateless/02015_async_inserts_7.sh