From c5f52714fb6327af28a9357531cb4b36d9b67802 Mon Sep 17 00:00:00 2001 From: anand76 Date: Fri, 26 Mar 2021 15:48:56 -0700 Subject: [PATCH] Use malloc in rocksdb_transaction_get_snapshot (#8114) Summary: The snapshot structure returned by rocksdb_transaction_get_snapshot is supposed to be freed by calling rocksdb_free(), so allocate using malloc rather than new. Fixes https://github.com/facebook/rocksdb/issues/6112 Pull Request resolved: https://github.com/facebook/rocksdb/pull/8114 Reviewed By: akankshamahajan15 Differential Revision: D27362923 Pulled By: anand1976 fbshipit-source-id: e93a8b1ffe26dafbe22529907f72b796ae971214 --- db/c.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/c.cc b/db/c.cc index 0f9d52010..73c9db501 100644 --- a/db/c.cc +++ b/db/c.cc @@ -4790,7 +4790,10 @@ void rocksdb_transaction_destroy(rocksdb_transaction_t* txn) { const rocksdb_snapshot_t* rocksdb_transaction_get_snapshot( rocksdb_transaction_t* txn) { - rocksdb_snapshot_t* result = new rocksdb_snapshot_t; + // This will be freed later on using free, so use malloc here to avoid a + // mismatch + rocksdb_snapshot_t* result = + (rocksdb_snapshot_t*)malloc(sizeof(rocksdb_snapshot_t)); result->rep = txn->rep->GetSnapshot(); return result; }