]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/request.c
Fixed libldap default connection concurrency issue (ITS#4541)
[openldap] / libraries / libldap / request.c
index 5cbac2c3ad44726ab66bbd15b74d753d7ee482d3..55f43b80287e923bb4281e4c52100b7b7b87f196 100644 (file)
@@ -93,19 +93,25 @@ ldap_send_initial_request(
        BerElement *ber,
        ber_int_t msgid)
 {
-       int rc;
+       int rc = 1;
 
        Debug( LDAP_DEBUG_TRACE, "ldap_send_initial_request\n", 0, 0, 0 );
 
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
        if ( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
                /* not connected yet */
-               int rc = ldap_open_defconn( ld );
-
-               if( rc < 0 ) {
-                       ber_free( ber, 1 );
-                       return( -1 );
-               }
+               rc = ldap_open_defconn( ld );
 
+       }
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
+       if( rc < 0 ) {
+               ber_free( ber, 1 );
+               return( -1 );
+       } else if ( rc == 0 ) {
                Debug( LDAP_DEBUG_TRACE,
                        "ldap_open_defconn: successful\n",
                        0, 0, 0 );