From 62504d7ef08e896ebbc7ef4b52157403adcbefa9 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 27 Aug 2007 07:11:32 +0000 Subject: [PATCH] add anlist_free --- servers/slapd/ad.c | 24 ++++++++++++++++++++---- servers/slapd/proto-slap.h | 3 +++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/servers/slapd/ad.c b/servers/slapd/ad.c index 4dcce9372e..0e79845f37 100644 --- a/servers/slapd/ad.c +++ b/servers/slapd/ad.c @@ -963,10 +963,8 @@ str2anlist( AttributeName *an, char *in, const char *brkstr ) return( an ); reterr: - for ( i = 0; an[i].an_name.bv_val; i++ ) { - free( an[i].an_name.bv_val ); - } - free( an ); + anlist_free( an, 1, NULL ); + /* * overwrites input string * on error! @@ -976,6 +974,24 @@ reterr: return NULL; } +void +anlist_free( AttributeName *an, int freename, void *ctx ) +{ + if ( an == NULL ) { + return; + } + + if ( freename ) { + int i; + + for ( i = 0; an[i].an_name.bv_val; i++ ) { + ber_memfree_x( an[i].an_name.bv_val, ctx ); + } + } + + ber_memfree_x( an, ctx ); +} + char **anlist2charray_x( AttributeName *an, int dup, void *ctx ) { char **attrs; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 5d4bc930d5..e3fae5ded0 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -168,6 +168,9 @@ LDAP_SLAPD_F (AttributeDescription *) ad_find_tags LDAP_P(( LDAP_SLAPD_F (AttributeName *) str2anlist LDAP_P(( AttributeName *an, char *str, const char *brkstr )); +LDAP_SLAPD_F (void) anlist_free LDAP_P(( AttributeName *an, + int freename, void *ctx )); + LDAP_SLAPD_F (char **) anlist2charray_x LDAP_P(( AttributeName *an, int dup, void *ctx )); LDAP_SLAPD_F (char **) anlist2charray LDAP_P(( AttributeName *an, int dup )); -- 2.39.5