From 521fdb00cca97e168e0c167e9915f2a5a0e7e6c1 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Sun, 5 May 2013 14:26:05 +0200 Subject: [PATCH] Fix mdb_env_close(unopened MDB_env). Do not try to scan me_dbxs in a closed/never-opened MDB_env. Broken by 7d643d3acb94a6d7306330b550fce0e5755444a9 and 151c416b460b02cd96502a47189cda19ab651ada. --- libraries/liblmdb/mdb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 2cfd8b2..c8ef564 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -3548,7 +3548,7 @@ leave: return rc; } -/** Destroy resources from mdb_env_open() and clear our readers */ +/** Destroy resources from mdb_env_open(), clear our readers & DBIs */ static void mdb_env_close0(MDB_env *env, int excl) { @@ -3557,6 +3557,10 @@ mdb_env_close0(MDB_env *env, int excl) if (!(env->me_flags & MDB_ENV_ACTIVE)) return; + /* Doing this here since me_dbxs may not exist during mdb_env_close */ + for (i = env->me_maxdbs; --i > MAIN_DBI; ) + free(env->me_dbxs[i].md_name.mv_data); + free(env->me_dbflags); free(env->me_dbxs); free(env->me_path); @@ -3764,14 +3768,10 @@ void mdb_env_close(MDB_env *env) { MDB_page *dp; - int i; if (env == NULL) return; - for (i = env->me_maxdbs; --i > MAIN_DBI; ) - free(env->me_dbxs[i].md_name.mv_data); - VGMEMP_DESTROY(env); while ((dp = env->me_dpages) != NULL) { VGMEMP_DEFINED(&dp->mp_next, sizeof(dp->mp_next)); -- 2.7.4