LDAPreqinfo *bind )
{
LDAPRequest *lr;
- int incparent, rc;
+ int incparent, rc;
Debug( LDAP_DEBUG_TRACE, "ldap_send_server_request\n", 0, 0, 0 );
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 )
{
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 ) {
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++ ) {
}
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",
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 );
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;
}
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;
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 ) {
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;
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",
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 );
/*
+ * 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 );
}
+/*
+ * 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 );