From caba669e8834627f5547fc901566e28d8de8c0b7 Mon Sep 17 00:00:00 2001 From: mips64-el Date: Wed, 25 Oct 2023 01:30:50 +0200 Subject: [PATCH] Fix double free on commit database migration --- src/Cache.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index 8ad850ac..bfe27c30 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -1727,12 +1727,14 @@ Cache::runMigrations() auto txn = lmdb::txn::begin(env_, nullptr); auto mainDb = lmdb::dbi::open(txn); auto dbNames = lmdb::cursor::open(txn, mainDb); + bool doCommit = false; std::string_view dbName; while (dbNames.get(dbName, MDB_NEXT)) { if (!dbName.starts_with("olm_sessions.v2/")) continue; + doCommit = true; auto curveKey = dbName; curveKey.remove_prefix(std::string_view("olm_sessions.v2/").size()); @@ -1750,7 +1752,7 @@ Cache::runMigrations() oldDb.drop(txn, true); } - txn.commit(); + if (doCommit) txn.commit(); } catch (const lmdb::error &e) { nhlog::db()->critical("Failed to convert olm sessions database in migration! {}", e.what());