]> git.sur5r.net Git - openldap/commitdiff
ITS#7292 plug memleak in control values
authorHoward Chu <hyc@openldap.org>
Thu, 7 Jun 2012 19:02:41 +0000 (12:02 -0700)
committerHoward Chu <hyc@openldap.org>
Thu, 7 Jun 2012 20:18:31 +0000 (13:18 -0700)
servers/slapd/controls.c
servers/slapd/proto-slap.h
servers/slapd/result.c

index e737afb043a8caeedd8ee14ec357b556c9477fb7..7d82cc45303191818eb4cffa6c53296d4451c3d3 100644 (file)
@@ -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,
index 198303d786f052c3e9c835e5b3c0fd1a7d6d63d4..51bf2d673a0149b7fc394ac21654ab273c20074a 100644 (file)
@@ -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,
index f42985f7cd758824cdd5c30451a1d1e596706664..0f1dca9f0aba2471d56972b7da31795ac39e7b3e 100644 (file)
@@ -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;
                }
        }