From: Hallvard Furuseth Date: Mon, 1 Dec 2014 07:59:29 +0000 (+0100) Subject: Fix robust mutexes - repair mti_txnid. X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=443a7e40c4280cfd07cbf80c5de62ea072b136e3;p=openldap Fix robust mutexes - repair mti_txnid. Broken by e3b6c359a935283c21e1fd7d03b790d87d53b933, if commit() crashes in write_meta before setting mti_txnid. --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 51d97d6d31..9b7f65586a 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -9492,7 +9492,7 @@ static int mdb_reader_check0(MDB_env *env, int rlocked, int *dead) */ static int mdb_mutex_failed(MDB_env *env, mdb_mutex_t *mutex, int rc) { - int rlocked, rc2; + int toggle, rlocked, rc2; #ifndef _WIN32 enum { WAIT_ABANDONED = EOWNERDEAD }; #endif @@ -9502,6 +9502,11 @@ static int mdb_mutex_failed(MDB_env *env, mdb_mutex_t *mutex, int rc) rc = MDB_SUCCESS; rlocked = (mutex == MDB_MUTEX(env, r)); if (!rlocked) { + /* Keep mti_txnid updated, otherwise next writer can + * overwrite data which latest meta page refers to. + */ + toggle = mdb_env_pick_meta(env); + env->me_txns->mti_txnid = env->me_metas[toggle]->mm_txnid; /* env is hosed if the dead thread was ours */ if (env->me_txn) { env->me_flags |= MDB_FATAL_ERROR;