From: Kurt Zeilenga Date: Mon, 30 Aug 1999 01:24:33 +0000 (+0000) Subject: Do not overwrite charray argument if charray_add realloc fails. X-Git-Tag: TWEB_OL_BASE~75 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=878d489ea9c56f2818c1f9bb9ab7cfad6edb96b7;p=openldap Do not overwrite charray argument if charray_add realloc fails. Caller is required to call ldap_charray_free as needed. --- diff --git a/libraries/libldap/charray.c b/libraries/libldap/charray.c index fefe1d9166..538aa02a4f 100644 --- a/libraries/libldap/charray.c +++ b/libraries/libldap/charray.c @@ -24,17 +24,27 @@ ldap_charray_add( if ( *a == NULL ) { *a = (char **) LDAP_MALLOC( 2 * sizeof(char *) ); n = 0; + + if( *a == NULL ) { + return -1; + } + } else { + char **new; + for ( n = 0; *a != NULL && (*a)[n] != NULL; n++ ) { ; /* NULL */ } - *a = (char **) LDAP_REALLOC( (char *) *a, + new = (char **) LDAP_REALLOC( (char *) *a, (n + 2) * sizeof(char *) ); - } - if( *a == NULL ) { - return -1; + if( new == NULL ) { + /* caller is required to call ldap_charray_free(*a) */ + return -1; + } + + *a = new; } (*a)[n] = LDAP_STRDUP(s);