Merge pull request #1594 from mips64-el/master

Fix double free on commit database migration
This commit is contained in:
DeepBlueV7.X 2023-10-25 15:38:13 +00:00 committed by GitHub
commit 7dd90ed6f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1727,12 +1727,14 @@ Cache::runMigrations()
auto txn = lmdb::txn::begin(env_, nullptr); auto txn = lmdb::txn::begin(env_, nullptr);
auto mainDb = lmdb::dbi::open(txn); auto mainDb = lmdb::dbi::open(txn);
auto dbNames = lmdb::cursor::open(txn, mainDb); auto dbNames = lmdb::cursor::open(txn, mainDb);
bool doCommit = false;
std::string_view dbName; std::string_view dbName;
while (dbNames.get(dbName, MDB_NEXT)) { while (dbNames.get(dbName, MDB_NEXT)) {
if (!dbName.starts_with("olm_sessions.v2/")) if (!dbName.starts_with("olm_sessions.v2/"))
continue; continue;
doCommit = true;
auto curveKey = dbName; auto curveKey = dbName;
curveKey.remove_prefix(std::string_view("olm_sessions.v2/").size()); curveKey.remove_prefix(std::string_view("olm_sessions.v2/").size());
@ -1750,7 +1752,7 @@ Cache::runMigrations()
oldDb.drop(txn, true); oldDb.drop(txn, true);
} }
txn.commit(); if (doCommit) txn.commit();
} catch (const lmdb::error &e) { } catch (const lmdb::error &e) {
nhlog::db()->critical("Failed to convert olm sessions database in migration! {}", nhlog::db()->critical("Failed to convert olm sessions database in migration! {}",
e.what()); e.what());