Patch: lru_mutex and c_rwlock bugs in back-bdb/cache.c (ITS#1756) ================ Written by Hallvard B. Furuseth and placed into the public domain. This software is not subject to any license of the University of Oslo. ================ The first ldap_pvt_thread_mutex_unlock() in bdb_cache_add_entry_rw() should be ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); Also, bdb's mutexes and rdwr locks are never destroyed. Here is a patch. Hallvard B. Furuseth , April 2002. diff -u2 -r servers/slapd/back-bdb/cache.c~ servers/slapd/back-bdb/cache.c --- servers/slapd/back-bdb/cache.c~ Mon Apr 15 18:53:24 2002 +++ servers/slapd/back-bdb/cache.c Tue Apr 16 05:59:18 2002 @@ -168,5 +168,5 @@ int refcnt, freeit = 1; - /* set cache mutex */ + /* set cache lock */ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock ); @@ -194,5 +194,5 @@ BEI(e)->bei_state = CACHE_ENTRY_READY; - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); @@ -210,5 +210,5 @@ } else if ( BEI(e)->bei_state == CACHE_ENTRY_DELETED ) { if( refcnt > 0 ) { - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); @@ -229,5 +229,5 @@ } - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); @@ -244,5 +244,5 @@ } else { - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); @@ -305,5 +305,5 @@ e->e_dn, rw ? "w" : "r" )); #endif - /* set cache mutex */ + /* set cache lock */ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock ); @@ -311,6 +311,6 @@ if( bdb_cache_entry_private_init(e) != 0 ) { - /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->lru_mutex ); + /* free cache lock */ + ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); #ifdef NEW_LOGGING @@ -331,5 +331,5 @@ (AVL_CMP) entry_dn_cmp, avl_dup_error ) != 0 ) { - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); @@ -379,5 +379,5 @@ bdb_cache_entry_private_destroy(e); - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); return( -1 ); @@ -451,5 +451,5 @@ Entry *ee; - /* set cache mutex */ + /* set cache lock */ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock ); @@ -469,5 +469,5 @@ #endif - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); return( 1 ); @@ -502,5 +502,5 @@ } - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); return( -1 ); @@ -572,5 +572,5 @@ try_again: - /* set cache mutex */ + /* set cache lock */ ldap_pvt_thread_rdwr_rlock( &cache->c_rwlock ); @@ -599,5 +599,5 @@ assert(state != CACHE_ENTRY_UNDEFINED); - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock ); @@ -639,5 +639,5 @@ } else { - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock ); @@ -666,5 +666,5 @@ try_again: - /* set cache mutex */ + /* set cache lock */ ldap_pvt_thread_rdwr_rlock( &cache->c_rwlock ); @@ -689,5 +689,5 @@ assert(state != CACHE_ENTRY_UNDEFINED); - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock ); @@ -714,5 +714,5 @@ */ - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock ); @@ -756,5 +756,5 @@ } - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock ); @@ -781,5 +781,5 @@ int rc; - /* set cache mutex */ + /* set cache lock */ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock ); @@ -798,5 +798,5 @@ ldap_pvt_thread_mutex_unlock( &cache->lru_mutex ); - /* free cache mutex */ + /* free cache lock */ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); return( rc ); @@ -847,5 +847,5 @@ int rc; - /* set cache mutex */ + /* set cache lock */ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock ); ldap_pvt_thread_mutex_lock( &cache->lru_mutex ); diff -u2 -r servers/slapd/back-bdb/init.c~ servers/slapd/back-bdb/init.c --- servers/slapd/back-bdb/init.c~ Mon Apr 15 18:53:24 2002 +++ servers/slapd/back-bdb/init.c Tue Apr 16 05:50:58 2002 @@ -444,4 +444,12 @@ } +#ifdef BDB_HIER + ldap_pvt_thread_rdwr_destroy( &bdb->bi_tree_rdwr ); +#endif + ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock ); + ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex ); + ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex ); + ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex ); + return 0; }