]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/request.c
Happy New Year
[openldap] / libraries / libldap / request.c
index 3998168ff187598605c6509849dcce4b50ce3151..aa805108beb5f5dc08ceef14803ca24afd3c9b9d 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2014 The OpenLDAP Foundation.
+ * Copyright 1998-2018 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -128,7 +128,10 @@ ldap_send_initial_request(
        if ( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd ) == -1 ) {
                /* not connected yet */
                rc = ldap_open_defconn( ld );
-
+               if ( rc == 0 ) {
+                       ber_sockbuf_ctrl( ld->ld_defconn->lconn_sb,
+                               LBER_SB_OPT_GET_FD, &sd );
+               }
        }
        if ( ld->ld_defconn && ld->ld_defconn->lconn_status == LDAP_CONNST_CONNECTING )
                rc = ldap_int_check_async_open( ld, sd );
@@ -312,6 +315,7 @@ ldap_send_server_request(
                LDAP_MUTEX_UNLOCK( &ld->ld_options.ldo_mutex );
                if ( rc == -1 ) {
                        ld->ld_errno = LDAP_ENCODING_ERROR;
+                       ber_free( ber, 1 );
                        LDAP_CONN_UNLOCK_IF(m_noconn);
                        return rc;
                }
@@ -331,6 +335,7 @@ ldap_send_server_request(
                rc = -1;
        }
        if ( rc ) {
+               ber_free( ber, 1 );
                LDAP_CONN_UNLOCK_IF(m_noconn);
                return rc;
        }
@@ -485,6 +490,10 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc **srvlist, int use_ldsb,
                        if ( rc != -1 ) {
                                srv = *srvp;
 
+                               /* If we fully connected, async is moot */
+                               if ( rc == 0 )
+                                       async = 0;
+
                                if ( ld->ld_urllist_proc && ( !async || rc != -2 ) ) {
                                        ld->ld_urllist_proc( ld, srvlist, srvp, ld->ld_urllist_params );
                                }
@@ -503,6 +512,13 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc **srvlist, int use_ldsb,
                }
 
                lc->lconn_server = ldap_url_dup( srv );
+               if ( !lc->lconn_server ) {
+                       if ( !use_ldsb )
+                               ber_sockbuf_free( lc->lconn_sb );
+                       LDAP_FREE( (char *)lc );
+                       ld->ld_errno = LDAP_NO_MEMORY;
+                       return( NULL );
+               }
        }
 
        lc->lconn_status = async ? LDAP_CONNST_CONNECTING : LDAP_CONNST_CONNECTED;
@@ -1057,7 +1073,7 @@ static int ldap_int_nextref(
  *              The array will be free'd by this function when no longer needed
  *  (IN) sref != 0 if following search reference
  *  (OUT) errstrp = Place to return a string of referrals which could not be followed
- *  (OUT) hadrefp = 1 if sucessfully followed referral
+ *  (OUT) hadrefp = 1 if successfully followed referral
  *
  * Return value - number of referrals followed
  *
@@ -1434,6 +1450,7 @@ ldap_chase_referrals( LDAP *ld,
                    id, sref, srv, &rinfo.ri_request );
 
                if ( ber == NULL ) {
+                       ldap_free_urllist( srv );
                        return -1 ;
                }