From 5c3f806fcaadc49bce42b0bfd47d2af29e8610cd Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Thu, 30 Dec 2010 23:32:07 +0000 Subject: [PATCH] ITS#6758 Add rs_reinit(), rs_flush_entry() --- servers/slapd/proto-slap.h | 4 ++++ servers/slapd/result.c | 30 +++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 489b61c064..6f72f30f32 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1544,11 +1544,15 @@ LDAP_SLAPD_F (int) get_alias_dn LDAP_P(( # define rs_assert_ok(rs) ((void) (rs)) # define rs_assert_ready(rs) ((void) (rs)) # define rs_assert_done(rs) ((void) (rs)) +# define rs_reinit(rs) ((void) memset( rs, 0, sizeof(SlapReply) )) #endif LDAP_SLAPD_F (void) (rs_assert_ok) LDAP_P(( const SlapReply *rs )); LDAP_SLAPD_F (void) (rs_assert_ready) LDAP_P(( const SlapReply *rs )); LDAP_SLAPD_F (void) (rs_assert_done) LDAP_P(( const SlapReply *rs )); +LDAP_SLAPD_F (void) (rs_reinit) LDAP_P(( SlapReply *rs )); +LDAP_SLAPD_F (void) rs_flush_entry LDAP_P(( Operation *op, + SlapReply *rs, slap_overinst *on )); LDAP_SLAPD_F (void) rs_replace_entry LDAP_P(( Operation *op, SlapReply *rs, slap_overinst *on, Entry *e )); LDAP_SLAPD_F (int) rs_ensure_entry_modifiable LDAP_P(( Operation *op, diff --git a/servers/slapd/result.c b/servers/slapd/result.c index e8fa1262d0..0382dee21b 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -190,23 +190,39 @@ void } #endif /* LDAP_TEST || USE_RS_ASSERT */ -/* Set rs->sr_entry after obyeing and clearing sr_flags & REP_ENTRY_MASK. */ +/* Reset a used SlapReply whose contents has been flushed (freed/released) */ void -rs_replace_entry( Operation *op, SlapReply *rs, slap_overinst *on, Entry *e ) +(rs_reinit)( SlapReply *rs ) { - slap_mask_t e_flags = rs->sr_flags & REP_ENTRY_MUSTFLUSH; + rs_assert_done( rs ); + memset( rs, 0, sizeof(SlapReply) ); +} - if ( e_flags && rs->sr_entry != NULL ) { - RS_ASSERT( e_flags != REP_ENTRY_MUSTFLUSH ); - if ( !(e_flags & REP_ENTRY_MUSTRELEASE) ) { +/* Obey and clear rs->sr_flags & REP_ENTRY_MASK. Clear sr_entry if freed. */ +void +rs_flush_entry( Operation *op, SlapReply *rs, slap_overinst *on ) +{ + rs_assert_ok( rs ); + + if ( (rs->sr_flags & REP_ENTRY_MUSTFLUSH) && rs->sr_entry != NULL ) { + if ( !(rs->sr_flags & REP_ENTRY_MUSTRELEASE) ) { entry_free( rs->sr_entry ); } else if ( on != NULL ) { overlay_entry_release_ov( op, rs->sr_entry, 0, on ); } else { be_entry_release_rw( op, rs->sr_entry, 0 ); } + rs->sr_entry = NULL; } + rs->sr_flags &= ~REP_ENTRY_MASK; +} + +/* Set rs->sr_entry after obeying and clearing sr_flags & REP_ENTRY_MASK. */ +void +rs_replace_entry( Operation *op, SlapReply *rs, slap_overinst *on, Entry *e ) +{ + rs_flush_entry( op, rs, on ); rs->sr_entry = e; } @@ -219,7 +235,7 @@ int rs_ensure_entry_modifiable( Operation *op, SlapReply *rs, slap_overinst *on ) { if ( rs->sr_flags & REP_ENTRY_MODIFIABLE ) { - RS_ASSERT((rs->sr_flags & REP_ENTRY_MUSTFLUSH)==REP_ENTRY_MUSTBEFREED); + rs_assert_ok( rs ); return 0; } rs_replace_entry( op, rs, on, entry_dup( rs->sr_entry )); -- 2.39.5