]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9444 Manage sr_ref/sr_matched flags accordingly
authorOndřej Kuzník <ondra@mistotebe.net>
Tue, 9 Mar 2021 17:31:01 +0000 (17:31 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 18 Mar 2021 15:34:26 +0000 (15:34 +0000)
send_ldap_response() clears them immediately even if we never attached
the data to be freed, so when we reinstate them, the flags are gone and
the next send_ldap_response() doesn't consider freeing them.

servers/slapd/back-ldap/chain.c

index 710fe1367139b4a8f814afe1807e809b75788e09..969adf7fa2b9912b07b1e3b38579b2c185f5781a 100644 (file)
@@ -383,8 +383,8 @@ retry:;
 
                default:
                        /* remember the text before it's freed in ldap_back_op_result */
-                       if ( lb.lb_text ) {
-                               ber_memfree_x( lb.lb_text, op->o_tmpmemctx );
+                       if ( lb->lb_text ) {
+                               ber_memfree_x( lb->lb_text, op->o_tmpmemctx );
                        }
                        lb->lb_text = ber_strdup_x( rs->sr_text, op->o_tmpmemctx );
                        return rs->sr_err;
@@ -971,6 +971,7 @@ ldap_chain_response( Operation *op, SlapReply *rs )
        const char      *text = NULL;
        const char      *matched;
        BerVarray       ref;
+       slap_mask_t     flags = 0;
        struct berval   ndn = op->o_ndn;
 
        int             sr_err = rs->sr_err;
@@ -1034,6 +1035,9 @@ ldap_chain_response( Operation *op, SlapReply *rs )
        ref = rs->sr_ref;
        rs->sr_ref = NULL;
 
+       flags = rs->sr_flags & (REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED);
+       rs->sr_flags &= ~flags;
+
        /* we need this to know if back-ldap returned any result */
        lb.lb_lc = lc;
        sc2.sc_next = sc->sc_next;
@@ -1169,6 +1173,7 @@ cannot_chain:;
                                rs->sr_text = text;
                                rs->sr_matched = matched;
                                rs->sr_ref = ref;
+                               rs->sr_flags |= flags;
                        }
 #ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
                        break;
@@ -1189,6 +1194,8 @@ dont_chain:;
        rs->sr_text = text;
        rs->sr_matched = matched;
        rs->sr_ref = ref;
+       rs->sr_flags |= flags;
+
        op->o_bd = bd;
        op->o_callback = sc;
        op->o_ndn = ndn;