mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-06 10:46:21 +08:00
Add memctx param to build_new_dn(). cleanup DN leaks.
This commit is contained in:
parent
ece76c067f
commit
c58ac9d8f1
@ -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 :
|
||||
|
@ -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};
|
||||
|
@ -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
|
||||
|
@ -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 ) {
|
||||
|
@ -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;
|
||||
|
@ -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++ = ',';
|
||||
|
@ -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 ));
|
||||
|
||||
|
@ -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 );
|
||||
|
@ -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 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user