From: Howard Chu Date: Tue, 29 Apr 2003 21:09:02 +0000 (+0000) Subject: Free ber mem arrays in reverse order. (better for sl_free) X-Git-Tag: OPENLDAP_REL_ENG_2_2_0ALPHA~210 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=23b63aac392cff4a5101ceea2f5afdd89252b466;p=openldap Free ber mem arrays in reverse order. (better for sl_free) --- diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index 18832c9401..c4c8d74a02 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -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); }