From: Howard Chu Date: Tue, 20 May 2014 15:47:28 +0000 (-0700) Subject: Fix mdb_rebalance collapsing root X-Git-Tag: OPENLDAP_REL_ENG_2_4_40~132^2~13 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4b9aed26a5b1c0027b10d211c6e7270dbb1ade1c;p=openldap Fix mdb_rebalance collapsing root Shift the rest of the cursor stack as needed --- diff --git a/libraries/liblmdb/COPYRIGHT b/libraries/liblmdb/COPYRIGHT index 4482816cf5..e0eb484c7a 100644 --- a/libraries/liblmdb/COPYRIGHT +++ b/libraries/liblmdb/COPYRIGHT @@ -1,4 +1,4 @@ -Copyright 2011-2013 Howard Chu, Symas Corp. +Copyright 2011-2014 Howard Chu, Symas Corp. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index e0f551eba4..55b8a1dff1 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -7383,6 +7383,7 @@ mdb_rebalance(MDB_cursor *mc) } } } else if (IS_BRANCH(mp) && NUMKEYS(mp) == 1) { + int i; DPUTS("collapsing root page!"); rc = mdb_midl_append(&mc->mc_txn->mt_free_pgs, mp->mp_pgno); if (rc) @@ -7394,6 +7395,10 @@ mdb_rebalance(MDB_cursor *mc) mc->mc_db->md_depth--; mc->mc_db->md_branch_pages--; mc->mc_ki[0] = mc->mc_ki[1]; + for (i = 1; imc_db->md_depth; i++) { + mc->mc_pg[i] = mc->mc_pg[i+1]; + mc->mc_ki[i] = mc->mc_ki[i+1]; + } { /* Adjust other cursors pointing to mp */ MDB_cursor *m2, *m3; @@ -7406,7 +7411,6 @@ mdb_rebalance(MDB_cursor *mc) m3 = m2; if (m3 == mc || m3->mc_snum < mc->mc_snum) continue; if (m3->mc_pg[0] == mp) { - int i; m3->mc_snum--; m3->mc_top--; for (i=0; imc_snum; i++) {