diff --git a/src/core.c b/src/core.c index 8c305ea4..d9e7f7b9 100644 --- a/src/core.c +++ b/src/core.c @@ -14273,16 +14273,18 @@ again: } void mdbx_cursor_close(MDBX_cursor *mc) { - if (mc) { + if (likely(mc)) { mdbx_ensure(NULL, mc->mc_signature == MDBX_MC_LIVE || mc->mc_signature == MDBX_MC_READY4CLOSE); + MDBX_txn *const txn = mc->mc_txn; if (!mc->mc_backup) { + mc->mc_txn = NULL; /* Remove from txn, if tracked. * A read-only txn (!C_UNTRACK) may have been freed already, * so do not peek inside it. Only write txns track cursors. */ if (mc->mc_flags & C_UNTRACK) { - mdbx_cassert(mc, !(mc->mc_txn->mt_flags & MDBX_TXN_RDONLY)); - MDBX_cursor **prev = &mc->mc_txn->tw.cursors[mc->mc_dbi]; + mdbx_ensure(txn->mt_env, check_txn_rw(txn, 0) == MDBX_SUCCESS); + MDBX_cursor **prev = &txn->tw.cursors[mc->mc_dbi]; while (*prev && *prev != mc) prev = &(*prev)->mc_next; mdbx_cassert(mc, *prev == mc); @@ -14294,6 +14296,7 @@ void mdbx_cursor_close(MDBX_cursor *mc) { } else { /* Cursor closed before nested txn ends */ mdbx_cassert(mc, mc->mc_signature == MDBX_MC_LIVE); + mdbx_ensure(txn->mt_env, check_txn_rw(txn, 0) == MDBX_SUCCESS); mc->mc_signature = MDBX_MC_WAIT4EOT; } }