ITS#7364 also close the mutexes as needed

Otherwise a process that opens and closes an env more than once
will leak mutex handles. (WIN32/BSD)
vmware
Howard Chu 12 years ago
parent 46cf442700
commit 916995236e
  1. 10
      libraries/libmdb/mdb.c

@ -3154,7 +3154,16 @@ mdb_env_close(MDB_env *env)
for (i=0; i<env->me_txns->mti_numreaders; i++) for (i=0; i<env->me_txns->mti_numreaders; i++)
if (env->me_txns->mti_readers[i].mr_pid == pid) if (env->me_txns->mti_readers[i].mr_pid == pid)
env->me_txns->mti_readers[i].mr_pid = 0; env->me_txns->mti_readers[i].mr_pid = 0;
#ifdef _WIN32
CloseHandle(env->me_rmutex);
CloseHandle(env->me_wmutex);
/* Windows automatically destroys the mutexes when
* the last handle closes.
*/
#else
#ifdef USE_POSIX_SEM #ifdef USE_POSIX_SEM
sem_close(env->me_rmutex);
sem_close(env->me_wmutex);
{ int excl = 0; { int excl = 0;
if (!mdb_env_excl_lock(env, &excl) && excl) { if (!mdb_env_excl_lock(env, &excl) && excl) {
/* we are the only remaining user of the environment. /* we are the only remaining user of the environment.
@ -3163,6 +3172,7 @@ mdb_env_close(MDB_env *env)
sem_unlink(env->me_txns->mti_wmname); sem_unlink(env->me_txns->mti_wmname);
} }
} }
#endif
#endif #endif
munmap((void *)env->me_txns, (env->me_maxreaders-1)*sizeof(MDB_reader)+sizeof(MDB_txninfo)); munmap((void *)env->me_txns, (env->me_maxreaders-1)*sizeof(MDB_reader)+sizeof(MDB_txninfo));
} }

Loading…
Cancel
Save