From c58ac9d8f157ca984b2e31eb679e9b6be440abe3 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 24 Sep 2003 04:30:41 +0000 Subject: [PATCH] Add memctx param to build_new_dn(). cleanup DN leaks. --- servers/slapd/back-bdb/ctxcsn.c | 24 ++++++++++++------------ servers/slapd/back-bdb/modrdn.c | 2 +- servers/slapd/back-ldbm/modrdn.c | 2 +- servers/slapd/back-sql/modify.c | 2 +- servers/slapd/ctxcsn.c | 4 ++-- servers/slapd/dn.c | 5 +++-- servers/slapd/proto-slap.h | 3 ++- servers/slapd/syncrepl.c | 27 +++++++-------------------- servers/slapd/tools/slapadd.c | 4 +--- 9 files changed, 30 insertions(+), 43 deletions(-) diff --git a/servers/slapd/back-bdb/ctxcsn.c b/servers/slapd/back-bdb/ctxcsn.c index d1dc8f596d..293670417c 100644 --- a/servers/slapd/back-bdb/ctxcsn.c +++ b/servers/slapd/back-bdb/ctxcsn.c @@ -44,6 +44,7 @@ bdb_csn_commit( ) { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private; + struct berval ctxcsn_ndn = { 0, NULL }; EntryInfo *ctxcsn_ei = NULL; DB_LOCK ctxcsn_lock; struct berval max_committed_csn; @@ -59,16 +60,15 @@ bdb_csn_commit( e = ei->bei_e; } - bdb_cache_find_ndn( op, tid, op->o_bd->be_nsuffix, &ctxcsn_ei ); - bdb_cache_entryinfo_unlock( ctxcsn_ei ); - rc = bdb_cache_find_ndn( op, tid, &slap_ldapsync_cn_bv, &ctxcsn_ei ); - if ( rc == 0 ) { - rc = bdb_cache_find_id( op, tid, ctxcsn_ei->bei_id, &ctxcsn_ei, 1, - locker, &ctxcsn_lock ); - *ctxcsn_e = ctxcsn_ei->bei_e; - } else { - bdb_cache_entryinfo_unlock( ctxcsn_ei ); - } + build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], + (struct berval *)&slap_ldapsync_cn_bv, op->o_tmpmemctx ); + + rc = bdb_dn2entry( op, tid, &ctxcsn_ndn, &ctxcsn_ei, + 1, locker, &ctxcsn_lock ); + + *ctxcsn_e = ctxcsn_ei->bei_e; + + op->o_tmpfree( ctxcsn_ndn.bv_val, op->o_tmpmemctx ); slap_get_commit_csn( op, &max_committed_csn ); @@ -269,9 +269,9 @@ bdb_get_commit_csn( struct berval bv; sprintf( substr, "cn=syncrepl%d", op->o_bd->syncinfo->id ); ber_str2bv( substr, 0, 0, &bv ); - build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &bv ); + build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &bv, op->o_tmpmemctx ); } else { - build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv ); + build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, op->o_tmpmemctx ); } ctxcsn_retry : diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index ba0502f207..b744b98ffe 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -664,7 +664,7 @@ retry: /* transaction retry */ } /* Build target dn and make sure target entry doesn't exist already. */ - if (!new_dn.bv_val) build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn ); + if (!new_dn.bv_val) build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL ); if (!new_ndn.bv_val) { struct berval bv = {0, NULL}; diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 7200a7bc48..6897e34866 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -469,7 +469,7 @@ ldbm_back_modrdn( } /* Build target dn and make sure target entry doesn't exist already. */ - build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn ); + build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL ); dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, NULL ); #ifdef NEW_LOGGING diff --git a/servers/slapd/back-sql/modify.c b/servers/slapd/back-sql/modify.c index 152165fa87..ce587646a9 100644 --- a/servers/slapd/back-sql/modify.c +++ b/servers/slapd/back-sql/modify.c @@ -679,7 +679,7 @@ backsql_modrdn( Operation *op, SlapReply *rs ) goto modrdn_return; } - build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn ); + build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn, NULL ); rs->sr_err = dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, op->o_tmpmemctx ); if ( rs->sr_err != LDAP_SUCCESS ) { diff --git a/servers/slapd/ctxcsn.c b/servers/slapd/ctxcsn.c index 5b62f5bc90..5f19d8f608 100644 --- a/servers/slapd/ctxcsn.c +++ b/servers/slapd/ctxcsn.c @@ -137,7 +137,7 @@ slap_create_context_csn_entry( attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL ); - attr_merge_one( e, slap_schema.si_ad_cn, &slap_ldapsync_bv, NULL ); + attr_merge_one( e, slap_schema.si_ad_cn, (struct berval *)&slap_ldapsync_bv, NULL ); if ( context_csn ) { attr_merge_one( e, slap_schema.si_ad_contextCSN, @@ -148,7 +148,7 @@ slap_create_context_csn_entry( bv.bv_len = sizeof("{}")-1; attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL ); - build_new_dn( &e->e_name, &be->be_nsuffix[0], &slap_ldapsync_cn_bv ); + build_new_dn( &e->e_name, &be->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, NULL ); ber_dupbv( &e->e_nname, &e->e_name ); return e; diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index be518eec58..2a810a0f7f 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -819,7 +819,8 @@ rdnValidate( struct berval *rdn ) void build_new_dn( struct berval * new_dn, struct berval * parent_dn, - struct berval * newrdn ) + struct berval * newrdn, + void *memctx ) { char *ptr; @@ -829,7 +830,7 @@ build_new_dn( struct berval * new_dn, } new_dn->bv_len = parent_dn->bv_len + newrdn->bv_len + 1; - new_dn->bv_val = (char *) ch_malloc( new_dn->bv_len + 1 ); + new_dn->bv_val = (char *) sl_malloc( new_dn->bv_len + 1, memctx ); ptr = lutil_strcopy( new_dn->bv_val, newrdn->bv_val ); *ptr++ = ','; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index ca1ed0ef53..ed3762dd6f 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -427,7 +427,8 @@ LDAP_SLAPD_F (int) dn_rdnlen LDAP_P(( Backend *be, struct berval *dn )); LDAP_SLAPD_F (void) build_new_dn LDAP_P(( struct berval * new_dn, struct berval * parent_dn, - struct berval * newrdn )); + struct berval * newrdn, + void *memctx )); LDAP_SLAPD_F (void) dnParent LDAP_P(( struct berval *dn, struct berval *pdn )); diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 7b8206b5f9..e4366ea987 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -364,9 +364,8 @@ do_syncrepl( op.ors_tlimit = 0; op.ors_attrsonly = 0; op.ors_attrs = NULL; - op.ors_filter = str2filter( def_filter_str = "(objectClass=*)" ); - ber_str2bv( def_filter_str, strlen( def_filter_str ), 1, - &op.ors_filterstr ); + op.ors_filter = str2filter_x( &op, def_filter_str = "(objectClass=*)" ); + ber_str2bv( def_filter_str, 0, 0, &op.ors_filterstr ); si->conn = &conn; conn.c_send_ldap_result = slap_send_ldap_result; @@ -374,22 +373,15 @@ do_syncrepl( conn.c_send_search_reference = slap_send_search_reference; /* get syncrepl cookie of shadow replica from subentry */ - ber_str2bv( si->base, strlen(si->base), 1, &base_bv ); + ber_str2bv( si->base, 0, 0, &base_bv ); dnPrettyNormal( 0, &base_bv, &pbase, &nbase, op.o_tmpmemctx ); sprintf( substr, "cn=syncrepl%d", si->id ); - ber_str2bv( substr, strlen(substr), 1, &sub_bv ); + ber_str2bv( substr, 0, 0, &sub_bv ); dnPrettyNormal( 0, &sub_bv, &psubrdn, &nsubrdn, op.o_tmpmemctx ); - build_new_dn( &op.o_req_dn, &pbase, &psubrdn ); - build_new_dn( &op.o_req_ndn, &nbase, &nsubrdn ); - - ch_free( base_bv.bv_val ); - ch_free( pbase.bv_val ); - ch_free( nbase.bv_val ); - ch_free( sub_bv.bv_val ); - ch_free( psubrdn.bv_val ); - ch_free( nsubrdn.bv_val ); + build_new_dn( &op.o_req_dn, &pbase, &psubrdn, op.o_tmpmemctx ); + build_new_dn( &op.o_req_ndn, &nbase, &nsubrdn, op.o_tmpmemctx ); /* set callback function */ cb.sc_response = cookie_callback; @@ -401,11 +393,6 @@ do_syncrepl( ber_dupbv( &syncCookie_req, si->syncCookie ); - ch_free( op.o_req_dn.bv_val ); - ch_free( op.o_req_ndn.bv_val ); - filter_free( op.ors_filter ); - ch_free( op.ors_filterstr.bv_val ); - psub = be->be_nsuffix[0]; for ( n = 0; si->attrs[ n ] != NULL; n++ ) ; @@ -1405,7 +1392,7 @@ syncrepl_updateCookie( e = ( Entry * ) ch_calloc( 1, sizeof( Entry )); - build_new_dn( &sub_bv, pdn, &psubrdn ); + build_new_dn( &sub_bv, pdn, &psubrdn, NULL ); dnPrettyNormal( NULL, &sub_bv, &e->e_name, &e->e_nname, NULL ); ch_free( sub_bv.bv_val ); ch_free( psubrdn.bv_val ); diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index 87059a57b5..da006c28ea 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -268,7 +268,6 @@ main( int argc, char **argv ) if ( SLAP_LASTMOD(be) && update_ctxcsn == SLAP_TOOL_CTXCSN_BATCH && csn.bv_len > 0 ) { Entry *ctxcsn_e; ID ctxcsn_id; - struct berval ctxcsn_rdn = { 0, NULL }; struct berval ctxcsn_ndn = { 0, NULL }; int ret; struct berval bvtext; @@ -278,8 +277,7 @@ main( int argc, char **argv ) bvtext.bv_val = textbuf; bvtext.bv_val[0] = '\0'; - ber_str2bv( "cn=ldapsync", strlen( "cn=ldapsync" ), 0, &ctxcsn_rdn ); - build_new_dn( &ctxcsn_ndn, &be->be_nsuffix[0], &ctxcsn_rdn ); + build_new_dn( &ctxcsn_ndn, &be->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, NULL ); ctxcsn_id = be->be_dn2id_get( be, &ctxcsn_ndn ); if ( ctxcsn_id == NOID ) { -- 2.39.5