--- libraries/libldap/result.c 2005/10/12 01:10:47 1.99.2.10 +++ libraries/libldap/result.c 2005/11/14 18:06:06 1.99.2.11 @@ -1,5 +1,5 @@ /* result.c - wait for an ldap result */ -/* $OpenLDAP: pkg/ldap/libraries/libldap/result.c,v 1.99.2.9 2005/10/10 17:35:26 kurt Exp $ */ +/* $OpenLDAP: pkg/ldap/libraries/libldap/result.c,v 1.99.2.10 2005/10/12 01:10:47 kurt Exp $ */ /* This work is part of OpenLDAP Software . * * Copyright 1998-2005 The OpenLDAP Foundation. @@ -565,18 +565,33 @@ nextresp2: ber_len_t len; char *lr_res_error = NULL; +#ifdef LDAP_NULL_IS_NULL + if ( ber_scanf( &tmpber, "{eAA",/*}*/ &lderr, + &lr->lr_res_matched, &lr_res_error ) + != LBER_ERROR ) +#else /* ! LDAP_NULL_IS_NULL */ if ( ber_scanf( &tmpber, "{eaa",/*}*/ &lderr, &lr->lr_res_matched, &lr_res_error ) != LBER_ERROR ) +#endif /* ! LDAP_NULL_IS_NULL */ { if ( lr_res_error != NULL ) { - if ( lr->lr_res_error != NULL ) { - (void)ldap_append_referral( ld, &lr->lr_res_error, lr_res_error ); - LDAP_FREE( (char *)lr_res_error ); +#ifndef LDAP_NULL_IS_NULL + if ( lr_res_error[ 0 ] == '\0' ) { + LDAP_FREE( lr_res_error ); + lr_res_error = NULL; + } else +#endif /* ! LDAP_NULL_IS_NULL */ + { + if ( lr->lr_res_error != NULL ) { + (void)ldap_append_referral( ld, &lr->lr_res_error, lr_res_error ); + LDAP_FREE( (char *)lr_res_error ); - } else { - lr->lr_res_error = lr_res_error; + } else { + lr->lr_res_error = lr_res_error; + } } + lr_res_error = NULL; } /* Check if V3 referral */ @@ -649,16 +664,29 @@ nextresp2: */ if ( tag == LDAP_RES_SEARCH_RESULT ) refer_cnt = 0; +#ifdef LDAP_NULL_IS_NULL + } else if ( ber_scanf( &tmpber, "{eAA}", &lderr, + &lr->lr_res_matched, &lr_res_error ) + != LBER_ERROR ) +#else /* ! LDAP_NULL_IS_NULL */ } else if ( ber_scanf( &tmpber, "{eaa}", &lderr, &lr->lr_res_matched, &lr_res_error ) != LBER_ERROR ) +#endif /* ! LDAP_NULL_IS_NULL */ { if ( lr_res_error != NULL ) { - if ( lr->lr_res_error != NULL ) { - (void)ldap_append_referral( ld, &lr->lr_res_error, lr_res_error ); - LDAP_FREE( (char *)lr_res_error ); - } else { - lr->lr_res_error = lr_res_error; +#ifndef LDAP_NULL_IS_NULL + if ( lr_res_error[ 0 ] == '\0' ) { + LDAP_FREE( lr_res_error ); + } else +#endif /* ! LDAP_NULL_IS_NULL */ + { + if ( lr->lr_res_error != NULL ) { + (void)ldap_append_referral( ld, &lr->lr_res_error, lr_res_error ); + LDAP_FREE( (char *)lr_res_error ); + } else { + lr->lr_res_error = lr_res_error; + } } lr_res_error = NULL; } @@ -697,10 +725,19 @@ nextresp2: } else { lr->lr_res_errno = LDAP_PARTIAL_RESULTS; } -Debug( LDAP_DEBUG_TRACE, - "new result: res_errno: %d, res_error: <%s>, res_matched: <%s>\n", - lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "", - lr->lr_res_matched ? lr->lr_res_matched : "" ); + + Debug( LDAP_DEBUG_TRACE, "new result: " + "res_errno: %d, " + "res_error: <%s>, " + "res_matched: <%s>\n", + lr->lr_res_errno, + lr->lr_res_error ? lr->lr_res_error : "", + lr->lr_res_matched ? lr->lr_res_matched : "" ); + } + + /* in any case, don't leave any lr_res_error 'round */ + if ( lr_res_error ) { + LDAP_FREE( lr_res_error ); } }