From 74b6ab9029261fd380ef844f53e024265bfb8303 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 8 Apr 2006 11:01:19 +0000 Subject: [PATCH] more cleanup --- libraries/libldap/request.c | 80 ++++++++++++++++++++----------------- libraries/libldap/result.c | 33 ++++++++++++++- libraries/libldap/unbind.c | 2 +- 3 files changed, 77 insertions(+), 38 deletions(-) diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index 57f6ea9ab3..921d8aa760 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -179,7 +179,7 @@ ldap_send_server_request( LDAPreqinfo *bind ) { LDAPRequest *lr; - int incparent, rc; + int incparent, rc; Debug( LDAP_DEBUG_TRACE, "ldap_send_server_request\n", 0, 0, 0 ); @@ -545,25 +545,12 @@ ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind ) force, unbind, 0 ); if ( force || --lc->lconn_refcnt <= 0 ) { - if ( lc->lconn_status == LDAP_CONNST_CONNECTED ) { - ldap_mark_select_clear( ld, lc->lconn_sb ); - if ( unbind ) { - ldap_send_unbind( ld, lc->lconn_sb, - NULL, NULL ); - } - } - - if ( lc->lconn_ber != NULL ) { - ber_free( lc->lconn_ber, 1 ); - } - - ldap_int_sasl_close( ld, lc ); - - prevlc = NULL; + /* remove from connections list first */ #ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex ); + ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex ); #endif - for ( tmplc = ld->ld_conns; + + for ( prevlc = NULL, tmplc = ld->ld_conns; tmplc != NULL; tmplc = tmplc->lconn_next ) { @@ -578,8 +565,23 @@ ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind ) prevlc = tmplc; } #ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex ); + ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex ); #endif + + if ( lc->lconn_status == LDAP_CONNST_CONNECTED ) { + ldap_mark_select_clear( ld, lc->lconn_sb ); + if ( unbind ) { + ldap_send_unbind( ld, lc->lconn_sb, + NULL, NULL ); + } + } + + if ( lc->lconn_ber != NULL ) { + ber_free( lc->lconn_ber, 1 ); + } + + ldap_int_sasl_close( ld, lc ); + ldap_free_urllist( lc->lconn_server ); #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND if ( lc->lconn_krbinstance != NULL ) { @@ -601,9 +603,11 @@ ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind ) lr = lr_next; } } + if ( lc->lconn_sb != ld->ld_sb ) { ber_sockbuf_free( lc->lconn_sb ); } + if ( lc->lconn_rebind_queue != NULL) { int i; for( i = 0; lc->lconn_rebind_queue[i] != NULL; i++ ) { @@ -611,10 +615,13 @@ ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind ) } LDAP_FREE( lc->lconn_rebind_queue ); } + LDAP_FREE( lc ); + Debug( LDAP_DEBUG_TRACE, "ldap_free_connection: actually freed\n", 0, 0, 0 ); + } else { lc->lconn_lastused = time( NULL ); Debug( LDAP_DEBUG_TRACE, "ldap_free_connection: refcnt %d\n", @@ -751,6 +758,9 @@ void ldap_free_request( LDAP *ld, LDAPRequest *lr ) { LDAPRequest **ttmplr; +#ifdef LDAP_R_COMPILE + LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_req_mutex ); +#endif Debug( LDAP_DEBUG_TRACE, "ldap_free_request (origid %d, msgid %d)\n", lr->lr_origid, lr->lr_msgid, 0 ); @@ -845,7 +855,7 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char * Debug( LDAP_DEBUG_ANY, "more than %d referral hops (dropping)\n", ld->ld_refhoplimit, 0, 0 ); ld->ld_errno = LDAP_REFERRAL_LIMIT_EXCEEDED; - rc = -1; + rc = -1; goto done; } @@ -898,14 +908,13 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char * int looped = 0; int len = srv->lud_dn ? strlen( srv->lud_dn ) : 0; for ( lp = origreq; lp; ) { - if ( lp->lr_conn == lc ) { - if ( len == lp->lr_dn.bv_len - && len - && strncmp( srv->lud_dn, lp->lr_dn.bv_val, len ) == 0 ) - { - looped = 1; - break; - } + if ( lp->lr_conn == lc + && len == lp->lr_dn.bv_len + && len + && strncmp( srv->lud_dn, lp->lr_dn.bv_val, len ) == 0 ) + { + looped = 1; + break; } if ( lp == origreq ) { lp = lp->lr_child; @@ -1163,14 +1172,13 @@ ldap_chase_referrals( LDAP *ld, int looped = 0; int len = srv->lud_dn ? strlen( srv->lud_dn ) : 0; for (lp = lr; lp; lp = lp->lr_parent ) { - if ( lp->lr_conn == lc ) { - if ( len == lp->lr_dn.bv_len ) { - if ( len && strncmp( srv->lud_dn, lp->lr_dn.bv_val, - len )) - continue; - looped = 1; - break; - } + if ( lp->lr_conn == lc + && len == lp->lr_dn.bv_len + && len + && strncmp( srv->lud_dn, lp->lr_dn.bv_val, len ) == 0 ) + { + looped = 1; + break; } } if ( looped ) { diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c index 002b5a087d..83b2e7eed1 100644 --- a/libraries/libldap/result.c +++ b/libraries/libldap/result.c @@ -140,16 +140,22 @@ chkResponseList( int all) { LDAPMessage *lm, **lastlm, *nextlm; - /* + + /* * Look through the list of responses we have received on * this association and see if the response we're interested in * is there. If it is, return it. If not, call wait4msg() to * wait until it arrives or timeout occurs. */ +#ifdef LDAP_R_COMPILE + LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex ); +#endif + Debug( LDAP_DEBUG_TRACE, "ldap_chkResponseList ld %p msgid %d all %d\n", (void *)ld, msgid, all ); + lastlm = &ld->ld_responses; for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) { nextlm = lm->lm_next; @@ -238,6 +244,10 @@ wait4msg( assert( ld != NULL ); assert( result != NULL ); +#ifdef LDAP_R_COMPILE + LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex ); +#endif + #ifdef LDAP_DEBUG if ( timeout == NULL ) { Debug( LDAP_DEBUG_TRACE, "wait4msg ld %p msgid %d (infinite timeout)\n", @@ -416,6 +426,10 @@ try_read1msg( assert( lcp != NULL ); assert( *lcp != NULL ); +#ifdef LDAP_R_COMPILE + LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex ); +#endif + Debug( LDAP_DEBUG_TRACE, "read1msg: ld %p msgid %d all %d\n", (void *)ld, msgid, all ); @@ -1159,13 +1173,21 @@ ldap_msgdelete( LDAP *ld, int msgid ) /* + * ldap_abandoned + * * return 1 if message msgid is waiting to be abandoned, 0 otherwise + * + * expects ld_res_mutex to be locked */ static int ldap_abandoned( LDAP *ld, ber_int_t msgid ) { int i; +#ifdef LDAP_R_COMPILE + LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex ); +#endif + if ( ld->ld_abandoned == NULL ) return( 0 ); @@ -1177,11 +1199,20 @@ ldap_abandoned( LDAP *ld, ber_int_t msgid ) } +/* + * ldap_mark_abandoned + * + * expects ld_res_mutex to be locked + */ static int ldap_mark_abandoned( LDAP *ld, ber_int_t msgid ) { int i; +#ifdef LDAP_R_COMPILE + LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex ); +#endif + if ( ld->ld_abandoned == NULL ) return( -1 ); diff --git a/libraries/libldap/unbind.c b/libraries/libldap/unbind.c index ec4083b577..52d535f85c 100644 --- a/libraries/libldap/unbind.c +++ b/libraries/libldap/unbind.c @@ -106,7 +106,7 @@ ldap_ld_free( next = lm->lm_next; ldap_msgfree( lm ); } - + if ( ld->ld_abandoned != NULL ) { LDAP_FREE( ld->ld_abandoned ); ld->ld_abandoned = NULL; -- 2.39.5