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

mutex protection



I have been doing some testing of the Windows NT build and found a problem when a connection is cleared. It seems form the code in slapd/connection.c is not entirely thtead safe. One thread can call connection_destroy() while another calls connection_init(). The result (from my testing) is that the assertion "assert( connections[i].c_sb.sb_sd == -1 );" can fail in this case.
As a solution, I place an "ldap_pvt_thread_mutex_lock( &connections_mutex );" just after the beginning assertions in connection_destroy and an "ldap_pvt_thread_mutex_unlock( &connections_mutex );" immediately before connection_destroy() returns.

As I said, I have been testing this with the NT code, but I believe the same holds true for Unix builds (connection.c version in CVS archive is 1.35)
I've attached what I hope is the correct "cvs diff" for the patch.

+------------------------------------------------------------------+ 
| Paul Higgs      (NA/EBC/PEEW/F)                                  | 
| Ericsson Business Networks AB       tel: +46 (8) 4221734         | 
| S131 89 Stockholm, Sweden           fax: +46 (8) 4221010         | 
| Office: Augustendalsvagan 21                                     | 
|         Nacka Strand          e-mail: paul.higgs@ebc.ericsson.se | 
+------------------------------------------------------------------+ 

--- connection.c	1999/05/06 12:46:48	1.35
+++ connection.c	1999/05/11 09:26:44
@@ -322,6 +322,7 @@
     assert( c->c_conn_state != SLAP_C_INVALID );
     assert( c->c_ops == NULL );
 
+	ldap_pvt_thread_mutex_lock( &connections_mutex );
     c->c_struct_state = SLAP_C_UNUSED;
     c->c_conn_state = SLAP_C_INVALID;
 
@@ -359,6 +360,7 @@
 	}
 
    	lber_pvt_sb_destroy( &c->c_sb );
+	ldap_pvt_thread_mutex_unlock( &connections_mutex );
 }
 
 int connection_state_closing( Connection *c )