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));