]> git.sur5r.net Git - openldap/commitdiff
In connections_shutdown - check for Uninitialized struct first, since
authorHoward Chu <hyc@openldap.org>
Thu, 21 Dec 2006 06:06:32 +0000 (06:06 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 21 Dec 2006 06:06:32 +0000 (06:06 +0000)
attempting to lock an unint'd mutex may crash on some platforms. And
there is no chance for an unint'd conn to get init'd while shutdown
is occurring, so the unprotected check of struct state is safe.

servers/slapd/connection.c

index 4534075be1b80ed802a9bdb8f2c91d0d14fec399..c64ef4866ed2ffadf5d3398636c49ac6894fdbc3 100644 (file)
@@ -196,20 +196,22 @@ int connections_shutdown(void)
        ber_socket_t i;
 
        for ( i = 0; i < dtblsize; i++ ) {
-               ldap_pvt_thread_mutex_lock( &connections[i].c_mutex );
-               if( connections[i].c_struct_state == SLAP_C_USED ) {
-
-                       /* give persistent clients a chance to cleanup */
-                       if( connections[i].c_conn_state == SLAP_C_CLIENT ) {
-                               ldap_pvt_thread_pool_submit( &connection_pool,
-                               connections[i].c_clientfunc, connections[i].c_clientarg );
-                       } else {
-                               /* c_mutex is locked */
-                               connection_closing( &connections[i], "slapd shutdown" );
-                               connection_close( &connections[i] );
+               if( connections[i].c_struct_state != SLAP_C_UNINITIALIZED ) {
+                       ldap_pvt_thread_mutex_lock( &connections[i].c_mutex );
+                       if( connections[i].c_struct_state == SLAP_C_USED ) {
+
+                               /* give persistent clients a chance to cleanup */
+                               if( connections[i].c_conn_state == SLAP_C_CLIENT ) {
+                                       ldap_pvt_thread_pool_submit( &connection_pool,
+                                       connections[i].c_clientfunc, connections[i].c_clientarg );
+                               } else {
+                                       /* c_mutex is locked */
+                                       connection_closing( &connections[i], "slapd shutdown" );
+                                       connection_close( &connections[i] );
+                               }
                        }
+                       ldap_pvt_thread_mutex_unlock( &connections[i].c_mutex );
                }
-               ldap_pvt_thread_mutex_unlock( &connections[i].c_mutex );
        }
 
        return 0;