From b15eebf50be47e1899be31cd692ff35ff0036522 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 2 Jan 2002 13:03:46 +0000 Subject: [PATCH] Minor cleanup. bvarray_add should return success/fail, like ber_bvecadd does. --- servers/slapd/add.c | 4 ++-- servers/slapd/charray.c | 12 +++++++++--- servers/slapd/proto-slap.h | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 047a61cbf7..358cfd9725 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -218,7 +218,7 @@ do_add( Connection *conn, Operation *op ) send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL, ref ? ref : default_referral, NULL ); - bvarray_free( ref ); + if ( ref ) bvarray_free( ref ); goto done; } @@ -309,7 +309,7 @@ do_add( Connection *conn, Operation *op ) send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL, ref ? ref : defref, NULL ); - bvarray_free( ref ); + if ( ref ) bvarray_free( ref ); #endif } } else { diff --git a/servers/slapd/charray.c b/servers/slapd/charray.c index 4c61238b3a..c15c95ab63 100644 --- a/servers/slapd/charray.c +++ b/servers/slapd/charray.c @@ -229,7 +229,11 @@ slap_strcopy( return a-1; } -void +/* Unlike charray_add, bvarray_add does not make a new copy of the + * source string. Typically it is used where ber_bvecadd was before, + * and ber_bvecadd didn't duplicate its source either. + */ +int bvarray_add( struct berval **a, struct berval *bv @@ -248,10 +252,12 @@ bvarray_add( *a = (struct berval *) ch_realloc( (char *) *a, (n + 2) * sizeof(struct berval) ); } + if ( *a == NULL ) return -1; - ber_dupbv( (*a)+n, bv ); - n++; + (*a)[n++] = *bv; (*a)[n].bv_val = NULL; + + return 0; } void diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 8afd4c0bdc..ae0ff67101 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -278,7 +278,7 @@ LDAP_SLAPD_F (char **) str2charray LDAP_P(( const char *str, const char *brkstr LDAP_SLAPD_F (int) charray_strcmp LDAP_P(( const char **a1, const char **a2 )); LDAP_SLAPD_F (int) charray_strcasecmp LDAP_P(( const char **a1, const char **a2 )); -LDAP_SLAPD_F (void) bvarray_add LDAP_P(( BVarray *a, struct berval *bv )); +LDAP_SLAPD_F (int) bvarray_add LDAP_P(( BVarray *a, struct berval *bv )); LDAP_SLAPD_F (void) bvarray_free LDAP_P(( struct berval *a )); LDAP_SLAPD_F (char *) slap_strcopy LDAP_P(( -- 2.39.5