[Date Prev][Date Next] [Chronological] [Thread] [Top]

thread locking bug (ITS#2917)



Full_Name: Murray Armfield
Version: openldap-2.1.22
OS: NetBSD-current
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (144.132.89.253)


There is a bug in the thread mutex locking code in the
servers/slapd/back-bdb/init.c file.

This bug was exposed by the new thread/SA code in NetBSD-current which seems to
find
many existing bugs in many thread enabled userland programs. I am not due the
credit, just
asked to pass this one from the guy who does.

Patch follows...

--- servers/slapd/back-bdb/init.c.orig  2003-11-17 21:31:19.000000000 +0100
+++ servers/slapd/back-bdb/init.c
@@ -460,17 +460,19 @@ bdb_db_close( BackendDB *be )
        bdb_cache_release_all (&bdb->bi_cache);

 #ifdef SLAP_IDL_CACHE
-       ldap_pvt_thread_mutex_lock ( &bdb->bi_idl_tree_mutex );
-       entry = bdb->bi_idl_lru_head;
-       while ( entry != NULL ) {
-               next_entry = entry->idl_lru_next;
-               avl_delete( &bdb->bi_idl_tree, (caddr_t) entry,
bdb_idl_entry_cmp );
-               free( entry->idl );
-               free( entry->kstr.bv_val );
-               free( entry );
-               entry = next_entry;
+       if ( bdb->bi_idl_cache_max_size ) {
+               ldap_pvt_thread_mutex_lock ( &bdb->bi_idl_tree_mutex );
+               entry = bdb->bi_idl_lru_head;
+               while ( entry != NULL ) {
+                       next_entry = entry->idl_lru_next;
+                       avl_delete( &bdb->bi_idl_tree, (caddr_t) entry,
bdb_idl_entry_cmp );
+                       free( entry->idl );
+                       free( entry->kstr.bv_val );
+                       free( entry );
+                       entry = next_entry;
+               }
+               ldap_pvt_thread_mutex_unlock ( &bdb->bi_idl_tree_mutex );
        }
-       ldap_pvt_thread_mutex_unlock ( &bdb->bi_idl_tree_mutex );
 #endif

        return 0;