diff --git a/src/api-cursor.c b/src/api-cursor.c index 18396299..f5f09c20 100644 --- a/src/api-cursor.c +++ b/src/api-cursor.c @@ -690,11 +690,9 @@ MDBX_txn *mdbx_cursor_txn(const MDBX_cursor *mc) { if (unlikely(!mc || mc->signature != cur_signature_live)) return nullptr; MDBX_txn *txn = mc->txn; - if (unlikely(!txn || txn->signature != txn_signature)) + if (unlikely(!txn || txn->signature != txn_signature || (txn->flags & MDBX_TXN_FINISHED))) return nullptr; - if (unlikely(txn->flags & MDBX_TXN_FINISHED)) - return nullptr; - return txn; + return (txn->flags & MDBX_TXN_HAS_CHILD) ? txn->env->txn : txn; } MDBX_dbi mdbx_cursor_dbi(const MDBX_cursor *mc) { diff --git a/src/cursor.c b/src/cursor.c index 8a96387d..b313a78f 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -2347,14 +2347,21 @@ int cursor_check(const MDBX_cursor *mc, int txn_bad_bits) { (char *)mc - stack_top < (ptrdiff_t)globals.sys_pagesize * 4)); if (txn_bad_bits) { - int rc = check_txn(mc->txn, txn_bad_bits); + int rc = check_txn(mc->txn, txn_bad_bits & ~MDBX_TXN_HAS_CHILD); if (unlikely(rc != MDBX_SUCCESS)) { cASSERT(mc, rc != MDBX_RESULT_TRUE); return rc; } - if (unlikely(cursor_dbi_changed(mc))) - return MDBX_BAD_DBI; + if (likely((mc->txn->flags & MDBX_TXN_HAS_CHILD) == 0)) + return likely(!cursor_dbi_changed(mc)) ? MDBX_SUCCESS : MDBX_BAD_DBI; + + cASSERT(mc, (mc->txn->flags & MDBX_TXN_RDONLY) == 0 && mc->txn != mc->txn->env->txn && mc->txn->env->txn); + rc = dbi_check(mc->txn->env->txn, cursor_dbi(mc)); + if (unlikely(rc != MDBX_SUCCESS)) + return rc; + + cASSERT(mc, (mc->txn->flags & MDBX_TXN_RDONLY) == 0 && mc->txn == mc->txn->env->txn); } return MDBX_SUCCESS;