From 0c542682b179ff3571f82d864121b858d5e2a053 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 5 Feb 2007 20:32:44 +0000 Subject: [PATCH] Timeouts should not be malloc'd --- libraries/libldap/init.c | 5 ++--- libraries/libldap/ldap-int.h | 4 ++-- libraries/libldap/open.c | 12 ------------ libraries/libldap/options.c | 28 ++++------------------------ libraries/libldap/os-ip.c | 9 ++++----- libraries/libldap/os-local.c | 9 ++++----- libraries/libldap/request.c | 18 ++++++++---------- libraries/libldap/result.c | 5 +++-- libraries/libldap/unbind.c | 10 ---------- 9 files changed, 27 insertions(+), 73 deletions(-) diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index 2aa88936e0..345eb823d3 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -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 */ diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index 185cfa8aaf..a49d742724 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -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; diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index a243637fc4..5bf762a4e6 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -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 ); diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index 029a0a1a9d..3f0c1b2ca1 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -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: { diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index ecd4e831c7..4b7de9e690 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -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", diff --git a/libraries/libldap/os-local.c b/libraries/libldap/os-local.c index 4eb81930ad..4e3a19e5a2 100644 --- a/libraries/libldap/os-local.c +++ b/libraries/libldap/os-local.c @@ -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", diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index 76985f3d33..ee0ec5013b 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -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 */ diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c index 05d7aece47..994c52bad7 100644 --- a/libraries/libldap/result.c +++ b/libraries/libldap/result.c @@ -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 diff --git a/libraries/libldap/unbind.c b/libraries/libldap/unbind.c index af394e50b6..3e0bbab8f6 100644 --- a/libraries/libldap/unbind.c +++ b/libraries/libldap/unbind.c @@ -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 ); -- 2.39.5