Skip to content

Commit a9cb66b

Browse files
committed
[lmdb] Prevent double free on transaction abort
We had already fixed `commit`, fix `abort` as well.
1 parent 82f988b commit a9cb66b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/Database/lmdb/lmdb++.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,12 +1276,11 @@ class lmdb::txn {
12761276
* @post `handle() == nullptr`
12771277
*/
12781278
void commit() {
1279+
// INDEXSTOREDB START (prevent double free)
12791280
MDB_txn *hnd = _handle;
1280-
// Clear _handle before the call otherwise if an error is thrown then
1281-
// the destructor will do abort() which will be double-free since
1282-
// txn_commit will have already freed the handle object.
12831281
_handle = nullptr;
12841282
lmdb::txn_commit(hnd);
1283+
// INDEXSTOREDB END
12851284
}
12861285

12871286
/**
@@ -1290,8 +1289,11 @@ class lmdb::txn {
12901289
* @post `handle() == nullptr`
12911290
*/
12921291
void abort() noexcept {
1293-
lmdb::txn_abort(_handle);
1292+
// INDEXSTOREDB START (prevent double free)
1293+
MDB_txn *hnd = _handle;
12941294
_handle = nullptr;
1295+
lmdb::txn_abort(hnd);
1296+
// INDEXSTOREDB END
12951297
}
12961298

12971299
/**

0 commit comments

Comments
 (0)