--- libraries/libldap/result.c 2005/10/11 22:31:05 1.118 +++ libraries/libldap/result.c 2005/11/12 17:42:04 1.119 @@ -1,5 +1,5 @@ /* result.c - wait for an ldap result */ -/* $OpenLDAP: pkg/ldap/libraries/libldap/result.c,v 1.117 2005/10/11 22:23:31 hyc Exp $ */ +/* $OpenLDAP: pkg/ldap/libraries/libldap/result.c,v 1.118 2005/10/11 22:31:05 hyc 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 ); } }