]> git.sur5r.net Git - openldap/commitdiff
realloc fix
authorKurt Zeilenga <kurt@openldap.org>
Thu, 10 Oct 2002 03:20:28 +0000 (03:20 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Thu, 10 Oct 2002 03:20:28 +0000 (03:20 +0000)
libraries/liblber/memory.c

index 73b338e3b52f89f5fb16763e0d97026578bba32d..fb68dd5c14847b40475c9d2382e4fe93ee91feb7 100644 (file)
@@ -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;