From f38bf4b362b4b1580dc65a6e205c486bab4eeb9d Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 10 May 2006 13:03:42 +0000 Subject: [PATCH] plug leaks --- servers/slapd/controls.c | 43 ++++++++++++++++++++++++---------------- servers/slapd/root_dse.c | 29 +++++++++++++++------------ 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index 26e2461515..6c61000884 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -1161,6 +1161,7 @@ static int parseAssert ( rs->sr_err = get_filter( op, ber, (Filter **)&(op->o_assertion), &rs->sr_text); + (void) ber_free( ber, 1 ); if( rs->sr_err != LDAP_SUCCESS ) { if( rs->sr_err == SLAPD_DISCONNECT ) { rs->sr_err = LDAP_PROTOCOL_ERROR; @@ -1223,26 +1224,28 @@ static int parsePreRead ( return LDAP_OTHER; } + rs->sr_err = LDAP_SUCCESS; + siz = sizeof( AttributeName ); off = offsetof( AttributeName, an_name ); if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) { rs->sr_text = "preread control: decoding error"; - return LDAP_PROTOCOL_ERROR; + rs->sr_err = LDAP_PROTOCOL_ERROR; + goto done; } for( i=0; ildctl_iscritical ) { + rs->sr_err = slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy ); + if ( rs->sr_err != LDAP_SUCCESS && ctrl->ldctl_iscritical ) { rs->sr_text = dummy ? dummy : "postread control: unknown attributeType"; - return rc; + goto done; } } @@ -1252,8 +1255,9 @@ static int parsePreRead ( op->o_preread_attrs = an; - rs->sr_err = LDAP_SUCCESS; - return LDAP_SUCCESS; +done: + (void) ber_free( ber, 1 ); + return rs->sr_err; } static int parsePostRead ( @@ -1288,26 +1292,27 @@ static int parsePostRead ( return LDAP_OTHER; } + rs->sr_err = LDAP_SUCCESS; siz = sizeof( AttributeName ); off = offsetof( AttributeName, an_name ); if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) { rs->sr_text = "postread control: decoding error"; - return LDAP_PROTOCOL_ERROR; + rs->sr_err = LDAP_PROTOCOL_ERROR; + goto done; } for( i=0; ildctl_iscritical ) { + rs->sr_err = slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy ); + if ( rs->sr_err != LDAP_SUCCESS && ctrl->ldctl_iscritical ) { rs->sr_text = dummy ? dummy : "postread control: unknown attributeType"; - return rc; + goto done; } } @@ -1317,8 +1322,9 @@ static int parsePostRead ( op->o_postread_attrs = an; - rs->sr_err = LDAP_SUCCESS; - return LDAP_SUCCESS; +done: + (void) ber_free( ber, 1 ); + return rs->sr_err; } static int parseValuesReturnFilter ( @@ -1348,6 +1354,8 @@ static int parseValuesReturnFilter ( rs->sr_err = get_vrFilter( op, ber, (ValuesReturnFilter **)&(op->o_vrFilter), &rs->sr_text); + (void) ber_free( ber, 1 ); + if( rs->sr_err != LDAP_SUCCESS ) { if( rs->sr_err == SLAPD_DISCONNECT ) { rs->sr_err = LDAP_PROTOCOL_ERROR; @@ -1494,13 +1502,14 @@ static int parseSearchOptions ( return LDAP_OTHER; } - if ( (tag = ber_scanf( ber, "{i}", &search_flags )) == LBER_ERROR ) { + tag = ber_scanf( ber, "{i}", &search_flags ); + (void) ber_free( ber, 1 ); + + if ( tag == LBER_ERROR ) { rs->sr_text = "searchOptions control decoding error"; return LDAP_PROTOCOL_ERROR; } - (void) ber_free( ber, 1 ); - if ( search_flags & LDAP_SEARCH_FLAG_DOMAIN_SCOPE ) { if ( op->o_domain_scope != SLAP_CONTROL_NONE ) { rs->sr_text = "searchOptions control specified multiple times " diff --git a/servers/slapd/root_dse.c b/servers/slapd/root_dse.c index 356cbc78a6..9be7f5399b 100644 --- a/servers/slapd/root_dse.c +++ b/servers/slapd/root_dse.c @@ -235,15 +235,17 @@ root_dse_info( /* FIXME: is this really needed? */ BER_BVSTR( &val, "top" ); if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) { +fail: + entry_free( e ); return LDAP_OTHER; } BER_BVSTR( &val, "OpenLDAProotDSE" ); if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) { - return LDAP_OTHER; + goto fail; } if( attr_merge_one( e, ad_structuralObjectClass, &val, NULL ) ) { - return LDAP_OTHER; + goto fail; } LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { @@ -257,7 +259,7 @@ root_dse_info( &be->be_suffix[0], &be->be_nsuffix[0] ) ) { - return LDAP_OTHER; + goto fail; } continue; } @@ -266,7 +268,7 @@ root_dse_info( &be->be_suffix[0], & be->be_nsuffix[0] ) ) { - return LDAP_OTHER; + goto fail; } continue; } @@ -278,7 +280,7 @@ root_dse_info( &be->be_suffix[j], &be->be_nsuffix[0] ) ) { - return LDAP_OTHER; + goto fail; } } } @@ -287,19 +289,19 @@ root_dse_info( /* supportedControl */ if ( controls_root_dse_info( e ) != 0 ) { - return LDAP_OTHER; + goto fail; } /* supportedExtension */ if ( exop_root_dse_info( e ) != 0 ) { - return LDAP_OTHER; + goto fail; } #ifdef LDAP_SLAPI /* netscape supportedExtension */ for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) { if( attr_merge_one( e, ad_supportedExtension, bv, NULL ) ) { - return LDAP_OTHER; + goto fail; } } #endif /* LDAP_SLAPI */ @@ -310,7 +312,7 @@ root_dse_info( } if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) { - return LDAP_OTHER; + goto fail; } /* supportedLDAPVersion */ @@ -325,7 +327,7 @@ root_dse_info( val.bv_val = buf; val.bv_len = strlen( val.bv_val ); if( attr_merge_one( e, ad_supportedLDAPVersion, &val, NULL ) ) { - return LDAP_OTHER; + goto fail; } } @@ -337,7 +339,8 @@ root_dse_info( val.bv_val = supportedSASLMechanisms[i]; val.bv_len = strlen( val.bv_val ); if( attr_merge_one( e, ad_supportedSASLMechanisms, &val, NULL ) ) { - return LDAP_OTHER; + ldap_charray_free( supportedSASLMechanisms ); + goto fail; } } ldap_charray_free( supportedSASLMechanisms ); @@ -345,7 +348,7 @@ root_dse_info( if ( default_referral != NULL ) { if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) { - return LDAP_OTHER; + goto fail; } } @@ -355,7 +358,7 @@ root_dse_info( if( attr_merge( e, a->a_desc, a->a_vals, (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) ) { - return LDAP_OTHER; + goto fail; } } } -- 2.39.5