From: Kurt Zeilenga Date: Thu, 10 Oct 2002 03:20:28 +0000 (+0000) Subject: realloc fix X-Git-Tag: OPENLDAP_REL_ENG_2_1_6~28 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3d5e7733a8b01439402802003016135dacc4d320;p=openldap realloc fix --- diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index 73b338e3b5..fb68dd5c14 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -674,22 +674,32 @@ ber_bvarray_add( BerVarray *a, BerValue *bv ) return 0; } n = 0; + *a = (BerValue *) LBER_MALLOC( 2 * sizeof(BerValue) ); + if ( *a == NULL ) { + return -1; + } + } else { + BerVarray *atmp; BER_MEM_VALID( a ); for ( n = 0; *a != NULL && (*a)[n].bv_val != NULL; n++ ) { - ; /* NULL */ + ; /* just count them */ } if (bv == NULL) { return n; } - *a = (BerValue *) LBER_REALLOC( (char *) *a, + + *atmp = (BerValue *) LBER_REALLOC( (char *) *a, (n + 2) * sizeof(BerValue) ); - } - if ( *a == NULL ) { - return -1; + + if( *atmp == NULL ) { + return -1; + } + + *a = *atmp; } (*a)[n++] = *bv;