]> git.sur5r.net Git - openldap/commitdiff
Free ber mem arrays in reverse order. (better for sl_free)
authorHoward Chu <hyc@openldap.org>
Tue, 29 Apr 2003 21:09:02 +0000 (21:09 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 29 Apr 2003 21:09:02 +0000 (21:09 +0000)
libraries/liblber/memory.c

index 18832c940180a7b3ed691723fc288c881fa8b599..c4c8d74a02b7cbba2d07487c2d1a39d26a337037 100644 (file)
@@ -403,7 +403,11 @@ ber_bvecfree_x( struct berval **bv, void *ctx )
 
        BER_MEM_VALID( bv );
 
-       for ( i = 0; bv[i] != NULL; i++ ) {
+       /* count elements */
+       for ( i = 0; bv[i] != NULL; i++ ) ;
+
+       /* free in reverse order */
+       for ( i--; i >= 0; i-- ) {
                ber_bvfree_x( bv[i], ctx );
        }
 
@@ -708,7 +712,11 @@ ber_bvarray_free_x( BerVarray a, void *ctx )
        if (a) {
                BER_MEM_VALID( a );
 
-               for (i=0; a[i].bv_val; i++) {
+               /* count elements */
+               for (i=0; a[i].bv_val; i++) ;
+               
+               /* free in reverse order */
+               for (i--; i>=0; i--) {
                        ber_memfree_x(a[i].bv_val, ctx);
                }