From e26b196f690c7fb024ec81cad859c9745507ea4b Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 4 Jan 2011 13:08:28 +0000 Subject: [PATCH] fix cloak behavior; plug leak (ITS#6762) --- contrib/slapd-modules/cloak/cloak.c | 45 ++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/contrib/slapd-modules/cloak/cloak.c b/contrib/slapd-modules/cloak/cloak.c index b6746e9ce8..777906eb39 100644 --- a/contrib/slapd-modules/cloak/cloak.c +++ b/contrib/slapd-modules/cloak/cloak.c @@ -25,8 +25,8 @@ #include -#include -#include +#include "ac/string.h" +#include "ac/socket.h" #include "lutil.h" #include "slap.h" @@ -159,7 +159,7 @@ cloak_cfgen( ConfigArgs *c ) ci_next = *cip; } - *cip = (cloak_info_t *)ch_calloc( 1, sizeof( cloak_info_t ) ); + *cip = (cloak_info_t *)SLAP_CALLOC( 1, sizeof( cloak_info_t ) ); (*cip)->ci_oc = oc; (*cip)->ci_ad = ad; (*cip)->ci_next = ci_next; @@ -177,7 +177,7 @@ cloak_cfgen( ConfigArgs *c ) } static int -cloak_search_cb( Operation *op, SlapReply *rs ) +cloak_search_response_cb( Operation *op, SlapReply *rs ) { slap_callback *sc; cloak_info_t *ci; @@ -187,7 +187,6 @@ cloak_search_cb( Operation *op, SlapReply *rs ) assert( op && op->o_callback && rs ); if ( rs->sr_type != REP_SEARCH || !rs->sr_entry ) { - slap_freeself_cb( op, rs ); return ( SLAP_CB_CONTINUE ); } @@ -235,7 +234,7 @@ cloak_search_cb( Operation *op, SlapReply *rs ) if ( a->a_desc != ci->ci_ad ) continue; - Debug( LDAP_DEBUG_TRACE, "cloak_search_cb: cloak %s\n", + Debug( LDAP_DEBUG_TRACE, "cloak_search_response_cb: cloak %s\n", a->a_desc->ad_cname.bv_val, 0, 0 ); @@ -252,6 +251,16 @@ cloak_search_cb( Operation *op, SlapReply *rs ) return ( SLAP_CB_CONTINUE ); } +static int +cloak_search_cleanup_cb( Operation *op, SlapReply *rs ) +{ + if ( rs->sr_type == REP_RESULT || rs->sr_err != LDAP_SUCCESS ) { + slap_freeself_cb( op, rs ); + } + + return SLAP_CB_CONTINUE; +} + static int cloak_search( Operation *op, SlapReply *rs ) { @@ -265,8 +274,8 @@ cloak_search( Operation *op, SlapReply *rs ) return SLAP_CB_CONTINUE; sc = op->o_tmpcalloc( 1, sizeof( *sc ), op->o_tmpmemctx ); - sc->sc_response = cloak_search_cb; - sc->sc_cleanup = slap_freeself_cb; + sc->sc_response = cloak_search_response_cb; + sc->sc_cleanup = cloak_search_cleanup_cb; sc->sc_next = op->o_callback; sc->sc_private = ci; op->o_callback = sc; @@ -288,6 +297,25 @@ static ConfigTable cloakcfg[] = { { NULL, NULL, 0, 0, 0, ARG_IGNORED } }; +static int +cloak_db_destroy( + BackendDB *be, + ConfigReply *cr ) +{ + slap_overinst *on = (slap_overinst *)be->bd_info; + cloak_info_t *ci = (cloak_info_t *)on->on_bi.bi_private; + + for ( ; ci; ) { + cloak_info_t *tmp = ci; + ci = ci->ci_next; + SLAP_FREE( tmp ); + } + + on->on_bi.bi_private = NULL; + + return 0; +} + static ConfigOCs cloakocs[] = { { "( OLcfgCtOc:4.1 " "NAME 'olcCloakConfig' " @@ -305,6 +333,7 @@ int cloak_initialize( void ) { int rc; cloak_ovl.on_bi.bi_type = "cloak"; + cloak_ovl.on_bi.bi_db_destroy = cloak_db_destroy; cloak_ovl.on_bi.bi_op_search = cloak_search; cloak_ovl.on_bi.bi_cf_ocs = cloakocs; -- 2.39.5