From c25934a8dd0042177d6dd5df72e881558c6a2c8c Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 23 Mar 2017 20:37:24 +0000 Subject: [PATCH] mdbx: backport - fix xcursor after cursor_del (ITS#8622). Re-fix 6b1df0e4c7fadd21d1233d7157229b2d89ccaa04 from ITS#8406 Change-Id: I177bef20cfa4b464a38cb42d66b7134f84434490 --- src/mdbx.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index ee2ab1fe..ef7afcbb 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -7617,14 +7617,16 @@ static int mdbx_cursor_del0(MDB_cursor *mc) { if (mc->mc_db->md_flags & MDB_DUPSORT) { MDB_node *node = NODEPTR(m3->mc_pg[m3->mc_top], m3->mc_ki[m3->mc_top]); - /* If this node is a fake page, it needs to be reinited - * because its data has moved. But just reset mc_pg[0] - * if the xcursor is already live. + /* If this node has dupdata, it may need to be reinited + * because its data has moved. + * If the xcursor was not initd it must be reinited. + * Else if node points to a subDB, nothing is needed. */ - if ((node->mn_flags & (F_DUPDATA | F_SUBDATA)) == F_DUPDATA) { - if (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) - m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node); - else + if (node->mn_flags & F_DUPDATA) { + if (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) { + if (!(node->mn_flags & F_SUBDATA)) + m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node); + } else mdbx_xcursor_init1(m3, node); } }