I have uploaded the patch to ftp.openldap.org/incoming as ian-puleston-1708= 25.patch, and included it below.
The code that it adds is pretty much copied from ldap_free_connection:
diff --git libraries/libldap/open.c libraries/libldap/open.c index 11564f9..251289d 100644 --- libraries/libldap/open.c +++ libraries/libldap/open.c @@ -450,6 +450,31 @@ ldap_int_open_connection( --conn->lconn_refcnt; =20 if (rc !=3D LDAP_SUCCESS) { + /* report the failure to the connection callbacks *= / + { + struct ldapoptions *lo; + ldaplist *ll; + ldap_conncb *cb; + + lo =3D &ld->ld_options; + LDAP_MUTEX_LOCK( &lo->ldo_mutex ); + if ( lo->ldo_conn_cbs ) { + for ( ll=3Dlo->ldo_conn_cbs; ll; ll= =3Dll->ll_next ) { + cb =3D ll->ll_data; + cb->lc_del( ld, conn->lconn= _sb, cb ); + } + } + LDAP_MUTEX_UNLOCK( &lo->ldo_mutex ); + lo =3D LDAP_INT_GLOBAL_OPT(); + LDAP_MUTEX_LOCK( &lo->ldo_mutex ); + if ( lo->ldo_conn_cbs ) { + for ( ll=3Dlo->ldo_conn_cbs; ll; ll= =3Dll->ll_next ) { + cb =3D ll->ll_data; + cb->lc_del( ld, conn->lconn= _sb, cb ); + } + } + LDAP_MUTEX_UNLOCK( &lo->ldo_mutex ); + } return -1; } }