From 0e46e4a7af51eaf31845b373a86ea97349f04756 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Fri, 11 Apr 2003 05:27:30 +0000 Subject: [PATCH] Workaround for SLAPI impedence mismatch with new thread-local malloc; computed search rewriter plugins cannot use thread-local malloc --- servers/slapd/search.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 17096c28bf..6c30fe2b22 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -472,21 +472,36 @@ static int doPreSearchPluginFNs( Operation *op ) static int doSearchRewriteFNs( Operation *op ) { if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, op->o_pb ) == 0 ) { + Filter *f; + /* * The plugin can set the SLAPI_SEARCH_FILTER. * SLAPI_SEARCH_STRFILER is not normative. */ - slapi_pblock_get( op->o_pb, SLAPI_SEARCH_FILTER, (void *)&op->ors_filter); - op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx ); - filter2bv_x( op, op->ors_filter, &op->ors_filterstr ); + slapi_pblock_get( op->o_pb, SLAPI_SEARCH_FILTER, (void *)&f ); + if ( f != op->ors_filter ) { + /* Plugin modified filter. Is pointer comparison safe? */ + /* + * This is inefficient but it is not possible to expose the + * new memory allocation API through SLAPI. + * + * Further, the plugin should be responsible for freeing + * the original filter, but there is no way to communicate + * the memory context through the SLAPI filter free API. + */ + op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx ); + filter2bv_x( op, f, &op->ors_filterstr ); + filter_free_x( op, op->ors_filter ); + op->ors_filter = str2filter_x( op, op->ors_filterstr.bv_val ); #ifdef NEW_LOGGING - LDAP_LOG( OPERATION, ARGS, - "doSearchRewriteFNs: after compute_rewrite_search filter: %s\n", - op->ors_filterstr.bv_len ? op->ors_filterstr.bv_val : "empty", 0, 0 ); + LDAP_LOG( OPERATION, ARGS, + "doSearchRewriteFNs: after compute_rewrite_search filter: %s\n", + op->ors_filterstr.bv_len ? op->ors_filterstr.bv_val : "empty", 0, 0 ); #else - Debug( LDAP_DEBUG_ARGS, " after compute_rewrite_search filter: %s\n", - op->ors_filterstr.bv_len ? op->ors_filterstr.bv_val : "empty", 0, 0 ); + Debug( LDAP_DEBUG_ARGS, " after compute_rewrite_search filter: %s\n", + op->ors_filterstr.bv_len ? op->ors_filterstr.bv_val : "empty", 0, 0 ); #endif + } } return LDAP_SUCCESS; -- 2.39.5