From: Howard Chu Date: Thu, 23 Aug 2012 06:01:19 +0000 (-0700) Subject: ITS#7364 also close the mutexes as needed X-Git-Tag: OPENLDAP_REL_ENG_2_4_33~34^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=916995236ed5979b971615ecc763745c187d37f6;p=openldap 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) --- diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index a120a52648..f8211c6019 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -3154,7 +3154,16 @@ mdb_env_close(MDB_env *env) for (i=0; ime_txns->mti_numreaders; i++) if (env->me_txns->mti_readers[i].mr_pid == pid) 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 + sem_close(env->me_rmutex); + sem_close(env->me_wmutex); { int excl = 0; if (!mdb_env_excl_lock(env, &excl) && excl) { /* 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); } } +#endif #endif munmap((void *)env->me_txns, (env->me_maxreaders-1)*sizeof(MDB_reader)+sizeof(MDB_txninfo)); }