From 23b63aac392cff4a5101ceea2f5afdd89252b466 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 29 Apr 2003 21:09:02 +0000 Subject: [PATCH] Free ber mem arrays in reverse order. (better for sl_free) --- libraries/liblber/memory.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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); } -- 2.39.5