]> git.sur5r.net Git - openldap/commitdiff
Timeouts should not be malloc'd
authorHoward Chu <hyc@openldap.org>
Mon, 5 Feb 2007 20:32:44 +0000 (20:32 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 5 Feb 2007 20:32:44 +0000 (20:32 +0000)
libraries/libldap/init.c
libraries/libldap/ldap-int.h
libraries/libldap/open.c
libraries/libldap/options.c
libraries/libldap/os-ip.c
libraries/libldap/os-local.c
libraries/libldap/request.c
libraries/libldap/result.c
libraries/libldap/unbind.c

index 2aa88936e06ed8d19e93e0df51be2ed1fe2d431b..345eb823d3f7bf4827086a384f214ff99bcbca88 100644 (file)
@@ -259,7 +259,6 @@ static void openldap_ldap_init_w_conf(
                        case ATTR_OPT_TV: {
                                struct timeval tv;
                                char *next;
-                               tv.tv_sec = -1;
                                tv.tv_usec = 0;
                                tv.tv_sec = strtol( opt, &next, 10 );
                                if ( next != opt && next[ 0 ] == '\0' && tv.tv_sec > 0 ) {
@@ -476,8 +475,8 @@ void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl
        gopts->ldo_timelimit = LDAP_NO_LIMIT;
        gopts->ldo_sizelimit = LDAP_NO_LIMIT;
 
-       gopts->ldo_tm_api = (struct timeval *)NULL;
-       gopts->ldo_tm_net = (struct timeval *)NULL;
+       gopts->ldo_tm_api.tv_sec = -1;
+       gopts->ldo_tm_net.tv_sec = -1;
 
        /* ldo_defludp will be freed by the termination handler
         */
index 185cfa8aaf35adb6f60a5f771dc1b4d980a475ea..a49d7427244fcf03ab084f69a904c5d3125d4b8f 100644 (file)
@@ -173,8 +173,8 @@ struct ldapoptions {
 #endif
 
        /* per API call timeout */
-       struct timeval          *ldo_tm_api;
-       struct timeval          *ldo_tm_net;
+       struct timeval          ldo_tm_api;
+       struct timeval          ldo_tm_net;
 
        ber_int_t               ldo_version;
        ber_int_t               ldo_deref;
index a243637fc41829fd9a05d5f57e21d112584616c2..5bf762a4e65d61f3a7ed50e745c37efc63716b82 100644 (file)
@@ -122,8 +122,6 @@ ldap_create( LDAP **ldp )
        /* but not pointers to malloc'ed items */
        ld->ld_options.ldo_sctrls = NULL;
        ld->ld_options.ldo_cctrls = NULL;
-       ld->ld_options.ldo_tm_api = NULL;
-       ld->ld_options.ldo_tm_net = NULL;
        ld->ld_options.ldo_defludp = NULL;
 
 #ifdef HAVE_CYRUS_SASL
@@ -146,14 +144,6 @@ ldap_create( LDAP **ldp )
        ld->ld_options.ldo_tls_ctx = NULL;
 #endif
 
-       if ( gopts->ldo_tm_api &&
-               ldap_int_timeval_dup( &ld->ld_options.ldo_tm_api, gopts->ldo_tm_api ))
-               goto nomem;
-
-       if ( gopts->ldo_tm_net &&
-               ldap_int_timeval_dup( &ld->ld_options.ldo_tm_net, gopts->ldo_tm_net ))
-               goto nomem;
-
        if ( gopts->ldo_defludp ) {
                ld->ld_options.ldo_defludp = ldap_url_duplist(gopts->ldo_defludp);
 
@@ -178,8 +168,6 @@ ldap_create( LDAP **ldp )
 nomem:
        ldap_free_select_info( ld->ld_selectinfo );
        ldap_free_urllist( ld->ld_options.ldo_defludp );
-       LDAP_FREE( ld->ld_options.ldo_tm_net );
-       LDAP_FREE( ld->ld_options.ldo_tm_api );
 #ifdef HAVE_CYRUS_SASL
        LDAP_FREE( ld->ld_options.ldo_def_sasl_authzid );
        LDAP_FREE( ld->ld_options.ldo_def_sasl_authcid );
index 029a0a1a9d838f4095e59221c26e0b268957ebf1..3f0c1b2ca1ab269517c7842c95d4381b16587ac7 100644 (file)
@@ -176,17 +176,11 @@ ldap_get_option(
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_TIMEOUT:
-               /* the caller has to free outvalue ! */
-               if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_api ) != 0 ) {
-                       return LDAP_OPT_ERROR;
-               }
+               *(struct timeval *) outvalue = lo->ldo_tm_api;
                return LDAP_OPT_SUCCESS;
                
        case LDAP_OPT_NETWORK_TIMEOUT:
-               /* the caller has to free outvalue ! */
-               if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_net ) != 0 ) {
-                       return LDAP_OPT_ERROR;
-               }
+               *(struct timeval *) outvalue = lo->ldo_tm_net;
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_DEREF:
@@ -452,28 +446,14 @@ ldap_set_option(
                        const struct timeval *tv = 
                                (const struct timeval *) invalue;
 
-                       if ( lo->ldo_tm_api != NULL ) {
-                               LDAP_FREE( lo->ldo_tm_api );
-                               lo->ldo_tm_api = NULL;
-                       }
-
-                       if ( ldap_int_timeval_dup( &lo->ldo_tm_api, tv ) != 0 ) {
-                               return LDAP_OPT_ERROR;
-                       }
+                       lo->ldo_tm_api = *tv;
                } return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_NETWORK_TIMEOUT: {
                        const struct timeval *tv = 
                                (const struct timeval *) invalue;
 
-                       if ( lo->ldo_tm_net != NULL ) {
-                               LDAP_FREE( lo->ldo_tm_net );
-                               lo->ldo_tm_net = NULL;
-                       }
-
-                       if ( ldap_int_timeval_dup( &lo->ldo_tm_net, tv ) != 0 ) {
-                               return LDAP_OPT_ERROR;
-                       }
+                       lo->ldo_tm_net = *tv;
                } return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_HOST_NAME: {
index ecd4e831c78b9cf7f82f4e7cc15bcf3a4df547bd..4b7de9e690f362c5b72c7c56b3a777f6d315e48a 100644 (file)
@@ -354,8 +354,7 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s,
        int async)
 {
        int rc, err;
-       struct timeval  tv = { 0 },
-                       *opt_tv = NULL;
+       struct timeval  tv, *opt_tv = NULL;
 
 #ifdef LDAP_CONNECTIONLESS
        /* We could do a connect() but that would interfere with
@@ -369,9 +368,9 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s,
                return ( 0 );
        }
 #endif
-       opt_tv = ld->ld_options.ldo_tm_net;
-       if ( opt_tv != NULL ) {
-               tv = *opt_tv;
+       if ( ld->ld_options.ldo_tm_net.tv_sec >= 0 ) {
+               tv = ld->ld_options.ldo_tm_net;
+               opt_tv = &tv;
        }
 
        osip_debug(ld, "ldap_pvt_connect: fd: %d tm: %ld async: %d\n",
index 4eb81930ad144653288ab74d3bd83c0ab07a9dff..4e3a19e5a29c20fa0fe19f1f73195f1996890230 100644 (file)
@@ -168,12 +168,11 @@ static int
 ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async)
 {
        int rc;
-       struct timeval  tv = { 0 },
-                       *opt_tv = NULL;
+       struct timeval  tv, *opt_tv = NULL;
 
-       opt_tv = ld->ld_options.ldo_tm_net;
-       if ( opt_tv != NULL ) {
-               tv = *opt_tv;
+       if ( ld->ld_options.ldo_tm_net.tv_sec >= 0 ) {
+               tv = ld->ld_options.ldo_tm_net;
+               opt_tv = &tv;
        }
 
        oslocal_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n",
index 76985f3d339a7fab654919f94267d5797d5667da..ee0ec5013b9d0c05c8f694d0639940677d9094d6 100644 (file)
@@ -223,18 +223,16 @@ ldap_send_server_request(
                        lc->lconn_status = LDAP_CONNST_CONNECTED;
                        break;
 
-               case -2: {
+               case -2:
                        /* async only occurs if a network timeout is set */
-                               struct timeval *tvp = ld->ld_options.ldo_tm_net;
-                               assert( tvp != NULL );
 
-                               /* honor network timeout */
-                               if ( time( NULL ) - lc->lconn_created <= tvp->tv_sec )
-                               {
-                                       /* caller will have to call again */
-                                       ld->ld_errno = LDAP_X_CONNECTING;
-                               }
-                       /* fallthru */
+                       /* honor network timeout */
+                       if ( time( NULL ) - lc->lconn_created <= ld->ld_options.ldo_tm_net.tv_sec )
+                       {
+                               /* caller will have to call again */
+                               ld->ld_errno = LDAP_X_CONNECTING;
+                       }
+                       /* fallthru */
 
                default:
                        /* error */
index 05d7aece47e66c37e2216cb511a0b910689b31d6..994c52bad79208bca9656baf7d50dc232473478c 100644 (file)
@@ -275,8 +275,9 @@ wait4msg(
        LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex );
 #endif
 
-       if ( timeout == NULL ) {
-               timeout = ld->ld_options.ldo_tm_api;
+       if ( timeout == NULL && ld->ld_options.ldo_tm_api.tv_sec >= 0 ) {
+               tv = ld->ld_options.ldo_tm_api;
+               timeout = &tv;
        }
 
 #ifdef LDAP_DEBUG
index af394e50b68df06d237bd12c6250bd5151561981..3e0bbab8f6b8de26d7d558bb807f05ed8f7732c2 100644 (file)
@@ -144,16 +144,6 @@ ldap_ld_free(
        }
 #endif
 
-       if ( ld->ld_options.ldo_tm_api != NULL ) {
-               LDAP_FREE( ld->ld_options.ldo_tm_api );
-               ld->ld_options.ldo_tm_api = NULL;
-       }
-
-       if ( ld->ld_options.ldo_tm_net != NULL ) {
-               LDAP_FREE( ld->ld_options.ldo_tm_net );
-               ld->ld_options.ldo_tm_net = NULL;
-       }
-
 #ifdef HAVE_CYRUS_SASL
        if ( ld->ld_options.ldo_def_sasl_mech != NULL ) {
                LDAP_FREE( ld->ld_options.ldo_def_sasl_mech );