From 9e3af2356ba3aee70682f2a328da73998ffab649 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 7 Jun 2012 12:02:41 -0700 Subject: [PATCH] ITS#7292 plug memleak in control values --- servers/slapd/controls.c | 15 ++++++++++++++- servers/slapd/proto-slap.h | 3 +++ servers/slapd/result.c | 6 +++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index e737afb043..7d82cc4530 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -566,11 +566,24 @@ void slap_free_ctrls( int i; for (i=0; ctrls[i]; i++) { - op->o_tmpfree(ctrls[i], op->o_tmpmemctx ); + op->o_tmpfree( ctrls[i], op->o_tmpmemctx ); } op->o_tmpfree( ctrls, op->o_tmpmemctx ); } +void slap_free_ctrl_vals( + Operation *op, + LDAPControl **ctrls ) +{ + int i; + + for (i=0; ctrls[i]; i++) { + if ( ctrls[i]->ldctl_value.bv_val ) + op->o_tmpfree( ctrls[i]->ldctl_value.bv_val, op->o_tmpmemctx ); + } + slap_free_ctrls( op, ctrls ); +} + int slap_add_ctrls( Operation *op, SlapReply *rs, diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 198303d786..51bf2d673a 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -638,6 +638,9 @@ LDAP_SLAPD_V( struct slap_control_ids ) slap_cids; LDAP_SLAPD_F (void) slap_free_ctrls LDAP_P(( Operation *op, LDAPControl **ctrls )); +LDAP_SLAPD_F (void) slap_free_ctrl_vals LDAP_P(( + Operation *op, + LDAPControl **ctrls )); LDAP_SLAPD_F (int) slap_add_ctrls LDAP_P(( Operation *op, SlapReply *rs, diff --git a/servers/slapd/result.c b/servers/slapd/result.c index f42985f7cd..0f1dca9f0a 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -752,7 +752,7 @@ clean2:; if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) { rs->sr_flags ^= REP_CTRLS_MUSTBEFREED; /* paranoia */ if ( rs->sr_ctrls ) { - slap_free_ctrls( op, rs->sr_ctrls ); + slap_free_ctrl_vals( op, rs->sr_ctrls ); rs->sr_ctrls = NULL; } } @@ -1476,7 +1476,7 @@ error_return:; if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) { rs->sr_flags ^= REP_CTRLS_MUSTBEFREED; /* paranoia */ if ( rs->sr_ctrls ) { - slap_free_ctrls( op, rs->sr_ctrls ); + slap_free_ctrl_vals( op, rs->sr_ctrls ); rs->sr_ctrls = NULL; } } @@ -1637,7 +1637,7 @@ rel: if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) { rs->sr_flags ^= REP_CTRLS_MUSTBEFREED; /* paranoia */ if ( rs->sr_ctrls ) { - slap_free_ctrls( op, rs->sr_ctrls ); + slap_free_ctrl_vals( op, rs->sr_ctrls ); rs->sr_ctrls = NULL; } } -- 2.39.5