]> git.sur5r.net Git - openldap/commitdiff
Do not overwrite charray argument if charray_add realloc fails.
authorKurt Zeilenga <kurt@openldap.org>
Mon, 30 Aug 1999 01:24:33 +0000 (01:24 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 30 Aug 1999 01:24:33 +0000 (01:24 +0000)
Caller is required to call ldap_charray_free as needed.

libraries/libldap/charray.c

index fefe1d916604a2c7362047ce8ec7047420607276..538aa02a4f541fc33654ab9d5d4a8cff3c905836 100644 (file)
@@ -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);