From: Howard Chu Date: Tue, 23 Sep 2003 22:52:35 +0000 (+0000) Subject: ITS#2735 - plug memory leaks X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~665 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=30f3b91ddcdf929c48753b69ed2bc3661e853d60;p=openldap ITS#2735 - plug memory leaks --- diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 6260b8164e..67b04cc6d5 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -37,7 +37,7 @@ bdb_add(Operation *op, SlapReply *rs ) Operation* ps_list; int rc; - EntryInfo *suffix_ei; + EntryInfo *suffix_ei = NULL; Entry *ctxcsn_e; int ctxcsn_added = 0; diff --git a/servers/slapd/back-bdb/ctxcsn.c b/servers/slapd/back-bdb/ctxcsn.c index c6655c11f1..d1dc8f596d 100644 --- a/servers/slapd/back-bdb/ctxcsn.c +++ b/servers/slapd/back-bdb/ctxcsn.c @@ -44,10 +44,9 @@ 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 = NULL; + struct berval max_committed_csn; DB_LOCK suffix_lock; int rc, ret; ID ctxcsn_id; @@ -60,17 +59,20 @@ bdb_csn_commit( e = ei->bei_e; } - build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], - (struct berval *)&slap_ldapsync_cn_bv ); - - rc = bdb_dn2entry( op, tid, &ctxcsn_ndn, &ctxcsn_ei, - 1, locker, &ctxcsn_lock ); - - *ctxcsn_e = ctxcsn_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 ); + } - max_committed_csn = slap_get_commit_csn( op ); + slap_get_commit_csn( op, &max_committed_csn ); - if ( max_committed_csn == NULL ) { + if ( max_committed_csn.bv_val == NULL ) { return BDB_CSN_COMMIT; } @@ -81,13 +83,14 @@ bdb_csn_commit( if ( !*ctxcsn_e ) { rs->sr_err = LDAP_OTHER; rs->sr_text = "context csn not present"; - ber_bvfree( max_committed_csn ); + ch_free( max_committed_csn.bv_val ); return BDB_CSN_ABORT; } else { Modifications mod; struct berval modvals[2]; + Entry dummy; - modvals[0] = *max_committed_csn; + modvals[0] = max_committed_csn; modvals[1].bv_val = NULL; modvals[1].bv_len = 0; @@ -98,11 +101,10 @@ bdb_csn_commit( mod.sml_type = mod.sml_desc->ad_cname; mod.sml_next = NULL; - bdb_cache_entry_db_relock( bdb->bi_dbenv, locker, ctxcsn_ei, 1, 0, &ctxcsn_lock ); - - ret = bdb_modify_internal( op, tid, &mod, *ctxcsn_e, - &rs->sr_text, textbuf, textlen ); - ber_bvfree( max_committed_csn ); + dummy = **ctxcsn_e; + ret = bdb_modify_internal( op, tid, &mod, &dummy, + &rs->sr_text, textbuf, textlen ); + ch_free( max_committed_csn.bv_val ); if ( ret != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ERR, @@ -120,7 +122,7 @@ bdb_csn_commit( } } - ret = bdb_id2entry_update( op->o_bd, tid, *ctxcsn_e ); + ret = bdb_id2entry_update( op->o_bd, tid, &dummy ); switch ( ret ) { case 0 : break; @@ -132,6 +134,7 @@ bdb_csn_commit( rs->sr_text = "context csn update failed"; return BDB_CSN_ABORT; } + bdb_cache_modify( *ctxcsn_e, dummy.e_attrs, bdb->bi_dbenv, locker, &ctxcsn_lock ); } break; case DB_NOTFOUND: @@ -159,8 +162,8 @@ bdb_csn_commit( return BDB_CSN_ABORT; } - *ctxcsn_e = slap_create_context_csn_entry( op->o_bd, max_committed_csn ); - ber_bvfree( max_committed_csn ); + *ctxcsn_e = slap_create_context_csn_entry( op->o_bd, &max_committed_csn ); + ch_free( max_committed_csn.bv_val ); (*ctxcsn_e)->e_id = ctxcsn_id; *ctxcsn_added = 1; diff --git a/servers/slapd/ctxcsn.c b/servers/slapd/ctxcsn.c index bcf7a4f687..5b62f5bc90 100644 --- a/servers/slapd/ctxcsn.c +++ b/servers/slapd/ctxcsn.c @@ -33,13 +33,18 @@ #include "slap.h" #include "lutil_ldap.h" -struct berval * -slap_get_commit_csn( Operation *op ) +const struct berval slap_ldapsync_bv = BER_BVC("ldapsync"); +const struct berval slap_ldapsync_cn_bv = BER_BVC("cn=ldapsync"); + +void +slap_get_commit_csn( Operation *op, struct berval *csn ) { - struct berval *max_committed_csn = NULL; struct slap_csn_entry *csne = NULL, *committed_csne = NULL; int i = 0; + csn->bv_val = NULL; + csn->bv_len = 0; + ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex ); LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) { @@ -61,10 +66,8 @@ slap_get_commit_csn( Operation *op ) ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex ); if ( committed_csne ) { - max_committed_csn = ber_dupbv( NULL, committed_csne->csn ); + ber_dupbv( csn, committed_csne->csn ); } - - return max_committed_csn; } void @@ -132,10 +135,7 @@ slap_create_context_csn_entry( attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL ); - bv.bv_val = "subentry"; - bv.bv_len = sizeof("subentry")-1; - - attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &bv, NULL ); + 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 );