[Bug 7853] Improve safety of mdb_env_close