From 2abaf7bf660539deb778b7ab43ad4ce8563e8556 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 16 Jun 2005 23:08:23 +0000 Subject: [PATCH] fix ITS#3788: don't free slapo-rwm callback, rather reuse it --- servers/slapd/overlays/rwm.c | 59 ++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/servers/slapd/overlays/rwm.c b/servers/slapd/overlays/rwm.c index 85d73d2ad0..28b9135287 100644 --- a/servers/slapd/overlays/rwm.c +++ b/servers/slapd/overlays/rwm.c @@ -583,6 +583,42 @@ rwm_op_modrdn( Operation *op, SlapReply *rs ) return SLAP_CB_CONTINUE; } +static slap_callback *rwm_cb; + +static void +rwm_keyfree( + void *key, + void *data ) +{ + ber_memfree_x( data, NULL ); +} + +static slap_callback * +rwm_callback_get( Operation *op ) +{ + void *data = NULL; + + if ( op->o_threadctx ) { + ldap_pvt_thread_pool_getkey( op->o_threadctx, + rwm_keyfree, &data, NULL ); + } else { + data = rwm_cb; + } + + if ( data == NULL ) { + data = ber_memalloc( sizeof( slap_callback ) ); + if ( op->o_threadctx ) { + ldap_pvt_thread_pool_setkey( op->o_threadctx, + rwm_keyfree, data, rwm_keyfree ); + + } else { + rwm_cb = (slap_callback *)data; + } + } + + return (slap_callback *)data; +} + static int rwm_swap_attrs( Operation *op, SlapReply *rs ) { @@ -594,18 +630,6 @@ rwm_swap_attrs( Operation *op, SlapReply *rs ) return SLAP_CB_CONTINUE; } -static int rwm_freeself( Operation *op, SlapReply *rs ) -{ - if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_RESULT ) { - assert( op->o_callback ); - - op->o_tmpfree( op->o_callback, op->o_tmpmemctx ); - op->o_callback = NULL; - } - - return SLAP_CB_CONTINUE; -} - static int rwm_op_search( Operation *op, SlapReply *rs ) { @@ -619,7 +643,7 @@ rwm_op_search( Operation *op, SlapReply *rs ) struct berval fstr = BER_BVNULL; Filter *f = NULL; - slap_callback *cb; + slap_callback *cb = NULL; AttributeName *an = NULL; char *text = NULL; @@ -679,15 +703,10 @@ rwm_op_search( Operation *op, SlapReply *rs ) goto error_return; } - cb = (slap_callback *) op->o_tmpcalloc( sizeof( slap_callback ), - 1, op->o_tmpmemctx ); - if ( cb == NULL ) { - rc = LDAP_NO_MEMORY; - goto error_return; - } + cb = rwm_callback_get( op ); cb->sc_response = rwm_swap_attrs; - cb->sc_cleanup = rwm_freeself; + cb->sc_cleanup = NULL; cb->sc_private = (void *)op->ors_attrs; cb->sc_next = op->o_callback; -- 2.39.5