mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-01 20:49:35 -05:00
Do not overwrite charray argument if charray_add realloc fails.
Caller is required to call ldap_charray_free as needed.
This commit is contained in:
parent
93c7bccde4
commit
878d489ea9
1 changed files with 14 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue