fix use-after-free

This commit is contained in:
Anton Popov 2021-10-24 22:32:28 +03:00
parent 6b34398e9c
commit 37de54937c
3 changed files with 8 additions and 2 deletions

View File

@ -407,14 +407,20 @@ try
} }
StreamingFormatExecutor executor(header, format, std::move(on_error), std::move(adding_defaults_transform)); StreamingFormatExecutor executor(header, format, std::move(on_error), std::move(adding_defaults_transform));
std::unique_ptr<ReadBuffer> buffer; std::unique_ptr<ReadBuffer> last_buffer;
for (const auto & entry : data->entries) for (const auto & entry : data->entries)
{ {
buffer = std::make_unique<ReadBufferFromString>(entry->bytes); auto buffer = std::make_unique<ReadBufferFromString>(entry->bytes);
current_entry = entry; current_entry = entry;
total_rows += executor.execute(*buffer); 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); auto chunk = Chunk(executor.getResultColumns(), total_rows);
size_t total_bytes = chunk.bytes(); size_t total_bytes = chunk.bytes();