From cd2520361d38ef3556d3bda479fd7a4caa0d1168 Mon Sep 17 00:00:00 2001 From: Jim Lin Date: Mon, 15 Jul 2019 12:55:37 -0700 Subject: [PATCH] Fix memorty leak in `rocksdb_wal_iter_get_batch` function (#5515) Summary: `wal_batch.writeBatchPtr.release()` gives up the ownership of the original `WriteBatch`, but there is no new owner, which causes memory leak. The patch is simple. Removing `release()` prevent ownership change. `std::move` is for speed. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5515 Differential Revision: D16264281 Pulled By: riversand963 fbshipit-source-id: 51c556b7a1c977325c3aa24acb636303847151fa --- db/c.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/c.cc b/db/c.cc index 17dc766dd6..4d40558f6b 100644 --- a/db/c.cc +++ b/db/c.cc @@ -1034,7 +1034,7 @@ void rocksdb_wal_iter_destroy (const rocksdb_wal_iterator_t* iter) { rocksdb_writebatch_t* rocksdb_wal_iter_get_batch (const rocksdb_wal_iterator_t* iter, uint64_t* seq) { rocksdb_writebatch_t* result = rocksdb_writebatch_create(); BatchResult wal_batch = iter->rep->GetBatch(); - result->rep = * wal_batch.writeBatchPtr.release(); + result->rep = std::move(*wal_batch.writeBatchPtr); if (seq != nullptr) { *seq = wal_batch.sequence; }