From 4d7c06cedf81ecb823e40ac600832d886ead9801 Mon Sep 17 00:00:00 2001 From: Giuseppe Ottaviano Date: Wed, 22 Feb 2017 17:40:06 -0800 Subject: [PATCH] Make WriteBatchWithIndex moveble Summary: `WriteBatchWithIndex` has an incorrect implicitly-generated move constructor (it will copy the pointer causing a double-free on destruction). Just switch to `unique_ptr` so we get correct move semantics for free. Closes https://github.com/facebook/rocksdb/pull/1899 Differential Revision: D4598896 Pulled By: ajkr fbshipit-source-id: 2373d47 --- include/rocksdb/utilities/write_batch_with_index.h | 3 ++- utilities/write_batch_with_index/write_batch_with_index.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/rocksdb/utilities/write_batch_with_index.h b/include/rocksdb/utilities/write_batch_with_index.h index 08852bc3d..8c519fe5c 100644 --- a/include/rocksdb/utilities/write_batch_with_index.h +++ b/include/rocksdb/utilities/write_batch_with_index.h @@ -12,6 +12,7 @@ #ifndef ROCKSDB_LITE +#include #include #include "rocksdb/comparator.h" @@ -205,7 +206,7 @@ class WriteBatchWithIndex : public WriteBatchBase { private: struct Rep; - Rep* rep; + std::unique_ptr rep; }; } // namespace rocksdb diff --git a/utilities/write_batch_with_index/write_batch_with_index.cc b/utilities/write_batch_with_index/write_batch_with_index.cc index 68c8d4c64..c92735fac 100644 --- a/utilities/write_batch_with_index/write_batch_with_index.cc +++ b/utilities/write_batch_with_index/write_batch_with_index.cc @@ -570,7 +570,7 @@ WriteBatchWithIndex::WriteBatchWithIndex( bool overwrite_key) : rep(new Rep(default_index_comparator, reserved_bytes, overwrite_key)) {} -WriteBatchWithIndex::~WriteBatchWithIndex() { delete rep; } +WriteBatchWithIndex::~WriteBatchWithIndex() {} WriteBatch* WriteBatchWithIndex::GetWriteBatch() { return &rep->write_batch; }