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
main
Giuseppe Ottaviano 7 years ago committed by Facebook Github Bot
parent 5040414e6f
commit 4d7c06cedf
  1. 3
      include/rocksdb/utilities/write_batch_with_index.h
  2. 2
      utilities/write_batch_with_index/write_batch_with_index.cc

@ -12,6 +12,7 @@
#ifndef ROCKSDB_LITE
#include <memory>
#include <string>
#include "rocksdb/comparator.h"
@ -205,7 +206,7 @@ class WriteBatchWithIndex : public WriteBatchBase {
private:
struct Rep;
Rep* rep;
std::unique_ptr<Rep> rep;
};
} // namespace rocksdb

@ -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; }

Loading…
Cancel
Save