]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/search.c
ITS#5860 - more for entry cache counts
[openldap] / servers / slapd / back-ldap / search.c
index 27e08e39eb22c0146a6f5168039f01c7ca0177f6..b3a68b31411e21f23fe4793354cf1e228e3138b6 100644 (file)
@@ -47,7 +47,8 @@ ldap_build_entry( Operation *op, LDAPMessage *e, Entry *ent,
 static int
 ldap_back_munge_filter(
        Operation       *op,
-       struct berval   *filter )
+       struct berval   *filter,
+       int     *freeit )
 {
        ldapinfo_t      *li = (ldapinfo_t *) op->o_bd->be_private;
 
@@ -122,6 +123,7 @@ ldap_back_munge_filter(
                        AC_MEMCPY( filter->bv_val, op->ors_filterstr.bv_val,
                                        op->ors_filterstr.bv_len + 1 );
 
+                       *freeit = 1;
                } else {
                        filter->bv_val = op->o_tmprealloc( filter->bv_val,
                                        filter->bv_len + 1, op->o_tmpmemctx );
@@ -163,7 +165,7 @@ ldap_back_search(
                        filter = BER_BVNULL;
        int             i;
        char            **attrs = NULL;
-       int             freetext = 0;
+       int             freetext = 0, freefilter = 0;
        int             do_retry = 1, dont_retry = 0;
        LDAPControl     **ctrls = NULL;
        char            **references = NULL;
@@ -242,7 +244,7 @@ retry:
                        goto finish;
 
                case LDAP_FILTER_ERROR:
-                       if (ldap_back_munge_filter( op, &filter ) > 0 ) {
+                       if (ldap_back_munge_filter( op, &filter, &freefilter ) > 0 ) {
                                goto retry;
                        }
 
@@ -561,7 +563,7 @@ finish:;
                ldap_back_quarantine( op, rs );
        }
 
-       if ( filter.bv_val != op->ors_filterstr.bv_val ) {
+       if ( freefilter && filter.bv_val != op->ors_filterstr.bv_val ) {
                op->o_tmpfree( filter.bv_val, op->o_tmpmemctx );
        }
 
@@ -766,7 +768,9 @@ ldap_build_entry(
                                        }
                                        attr->a_vals[i] = attr->a_vals[last];
                                        BER_BVZERO( &attr->a_vals[last] );
+                                       i--;
                                }
+
                        } else if ( pretty ) {
                                LBER_FREE( attr->a_vals[i].bv_val );
                                attr->a_vals[i] = pval;
@@ -801,6 +805,7 @@ ldap_build_entry(
                                        }
                                        attr->a_vals[i] = attr->a_vals[last];
                                        BER_BVZERO( &attr->a_vals[last] );
+                                       i--;
                                }
                        }
                        BER_BVZERO( &attr->a_nvals[i] );
@@ -834,7 +839,7 @@ ldap_build_entry(
                                }
                                BER_BVZERO(&attr->a_vals[attr->a_numvals]);
                                if ( attr->a_nvals != attr->a_vals )
-                                       BER_BVZERO(&attr->a_vals[attr->a_numvals]);
+                                       BER_BVZERO(&attr->a_nvals[attr->a_numvals]);
                        }
                        attr->a_flags |= SLAP_ATTR_SORTED_VALS;
                }