From 2c70d0430adc24b1afb59a265ffcc43a124e64ad Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 18 Sep 2011 14:18:27 -0700 Subject: [PATCH] Fix mdb_drop() if not deleting the DB record --- libraries/libmdb/mdb.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index aa5f2cd..6e829c8 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -5342,10 +5342,19 @@ int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del) mdb_cursor_close(mc); return rc; - if (del) { + /* Can't delete the main DB */ + if (del && dbi > MAIN_DBI) { rc = mdb_del(txn, MAIN_DBI, &mc->mc_dbx->md_name, NULL); if (!rc) mdb_close(txn->mt_env, dbi); + } else { + txn->mt_dbflags[dbi] |= DB_DIRTY; + txn->mt_dbs[dbi].md_depth = 0; + txn->mt_dbs[dbi].md_branch_pages = 0; + txn->mt_dbs[dbi].md_leaf_pages = 0; + txn->mt_dbs[dbi].md_overflow_pages = 0; + txn->mt_dbs[dbi].md_entries = 0; + txn->mt_dbs[dbi].md_root = P_INVALID; } mdb_cursor_close(mc); return rc;