]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9929 plug memleaks
authorHoward Chu <hyc@openldap.org>
Wed, 30 Nov 2022 19:28:04 +0000 (19:28 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Mon, 5 Dec 2022 16:32:49 +0000 (16:32 +0000)
servers/slapd/ava.c
servers/slapd/backend.c
servers/slapd/filter.c
servers/slapd/overlays/dynlist.c
servers/slapd/proto-slap.h

index 51d9cc101b63c3083c363c62ac7ce509bc5391c9..ae9351dfb3f6acfea6a1ae25952a26ec1c53353c 100644 (file)
@@ -53,6 +53,22 @@ ava_free(
        if ( freeit ) op->o_tmpfree( (char *) ava, op->o_tmpmemctx );
 }
 
+AttributeAssertion *
+ava_dup(
+       AttributeAssertion *ava,
+       void *memctx )
+{
+       BerMemoryFunctions *mf = &slap_sl_mfuncs;
+       AttributeAssertion *nava;
+
+       nava = mf->bmf_malloc( sizeof(AttributeAssertion), memctx );
+       *nava = *ava;
+       if ( ava->aa_desc->ad_flags & SLAP_DESC_TEMPORARY )
+               nava->aa_desc = slap_bv2tmp_ad( &ava->aa_desc->ad_cname, memctx );
+       ber_dupbv_x( &nava->aa_value, &ava->aa_value, memctx );
+       return nava;
+}
+
 int
 get_ava(
        Operation *op,
index cfe35aa532a40b82478c17bac49eb7cb2d15a2f0..30a32db7d32c983c071529fde0a0db8e9ccf9a22 100644 (file)
@@ -1593,7 +1593,7 @@ fe_acl_group(
                                                        if ( rc2 != 0 ) {
                                                                /* give up... */
                                                                rc = (rc2 == LDAP_NO_SUCH_OBJECT) ? rc2 : LDAP_OTHER;
-                                                               goto loopit;
+                                                               goto nouser;
                                                        }
                                                }
 
@@ -1602,6 +1602,7 @@ fe_acl_group(
                                                {
                                                        rc = 0;
                                                }
+nouser:
                                                filter_free_x( op, filter, 1 );
                                        }
 loopit:
index 1d7ee216a8b75c23de756cfebaa1f3e2a20a3f92..9d000bce07eeaa9c262aab4c6e1521a89fce53d5 100644 (file)
@@ -910,12 +910,7 @@ filter_dup( Filter *f, void *memctx )
        case LDAP_FILTER_GE:
        case LDAP_FILTER_LE:
        case LDAP_FILTER_APPROX:
-               /* Should this be ava_dup() ? */
-               n->f_ava = mf->bmf_calloc( 1, sizeof(AttributeAssertion), memctx );
-               *n->f_ava = *f->f_ava;
-               if ( f->f_av_desc->ad_flags & SLAP_DESC_TEMPORARY )
-                       n->f_av_desc = slap_bv2tmp_ad( &f->f_av_desc->ad_cname, memctx );
-               ber_dupbv_x( &n->f_av_value, &f->f_av_value, memctx );
+               n->f_ava = ava_dup( f->f_ava, memctx );
                break;
        case LDAP_FILTER_SUBSTRINGS:
                n->f_sub = mf->bmf_calloc( 1, sizeof(SubstringsAssertion), memctx );
index 5c971366f8f55939ea1d219a335eb2dbf43f42b6..3b1e38b13c87cf2e0e5e626a5a5e408e8e489ec9 100644 (file)
@@ -1338,47 +1338,32 @@ dynlist_filter_group( Operation *op, dynlist_name_t *dyn, Filter *n, dynlist_sea
 static Filter *
 dynlist_filter_dup( Operation *op, Filter *f, AttributeDescription *ad, dynlist_search_t *ds )
 {
-       Filter *n = NULL;
+       Filter *n;
 
        if ( !f )
                return NULL;
 
-       n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
-       n->f_next = NULL;
        switch( f->f_choice & SLAPD_FILTER_MASK ) {
-       case SLAPD_FILTER_COMPUTED:
-               n->f_choice = f->f_choice;
-               n->f_result = f->f_result;
-               break;
-
-       case LDAP_FILTER_PRESENT:
-               n->f_choice = f->f_choice;
-               n->f_desc = f->f_desc;
-               break;
-
        case LDAP_FILTER_EQUALITY:
+               n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
+               n->f_next = NULL;
                if ( f->f_av_desc == ad ) {
                        dynlist_name_t *dyn = ldap_tavl_find( ds->ds_names, &f->f_av_value, dynlist_avl_cmp );
                        n->f_choice = SLAPD_FILTER_COMPUTED;
                        if ( dyn && !dynlist_filter_group( op, dyn, n, ds ))
                                break;
                }
-               /* FALLTHRU */
+               n->f_choice = LDAP_FILTER_EQUALITY;
+               n->f_ava = ava_dup( f->f_ava, op->o_tmpmemctx );
+               break;
+       case SLAPD_FILTER_COMPUTED:
+       case LDAP_FILTER_PRESENT:
        case LDAP_FILTER_GE:
        case LDAP_FILTER_LE:
        case LDAP_FILTER_APPROX:
-               n->f_choice = f->f_choice;
-               n->f_ava = f->f_ava;
-               break;
-
        case LDAP_FILTER_SUBSTRINGS:
-               n->f_choice = f->f_choice;
-               n->f_sub = f->f_sub;
-               break;
-
        case LDAP_FILTER_EXT:
-               n->f_choice = f->f_choice;
-               n->f_mra = f->f_mra;
+               n = filter_dup( f, op->o_tmpmemctx );
                break;
 
        case LDAP_FILTER_NOT:
@@ -1386,6 +1371,8 @@ dynlist_filter_dup( Operation *op, Filter *f, AttributeDescription *ad, dynlist_
        case LDAP_FILTER_OR: {
                Filter **p;
 
+               n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
+               n->f_next = NULL;
                n->f_choice = f->f_choice;
 
                for ( p = &n->f_list, f = f->f_list; f; f = f->f_next ) {
@@ -1400,29 +1387,6 @@ dynlist_filter_dup( Operation *op, Filter *f, AttributeDescription *ad, dynlist_
        return n;
 }
 
-static void
-dynlist_filter_free( Operation *op, Filter *f )
-{
-       Filter *p, *next;
-
-       if ( f == NULL )
-               return;
-
-       f->f_choice &= SLAPD_FILTER_MASK;
-       switch( f->f_choice ) {
-       case LDAP_FILTER_AND:
-       case LDAP_FILTER_OR:
-       case LDAP_FILTER_NOT:
-               for ( p = f->f_list; p; p = next ) {
-                       next = p->f_next;
-                       op->o_tmpfree( p, op->o_tmpmemctx );
-               }
-               break;
-       default:
-               op->o_tmpfree( f, op->o_tmpmemctx );
-       }
-}
-
 static void
 dynlist_search_free( void *ptr )
 {
@@ -1457,7 +1421,7 @@ dynlist_search_cleanup( Operation *op, SlapReply *rs )
                        ldap_tavl_free( ds->ds_fnodes, NULL );
                if ( ds->ds_origfilter ) {
                        op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
-                       dynlist_filter_free( op, op->ors_filter );
+                       filter_free_x( op, op->ors_filter, 1 );
                        op->ors_filter = ds->ds_origfilter;
                        op->ors_filterstr = ds->ds_origfilterbv;
                }
@@ -1733,7 +1697,7 @@ dynlist_fix_filter( Operation *op, AttributeDescription *ad, dynlist_search_t *d
        Filter *f;
        f = dynlist_filter_dup( op, op->ors_filter, ad, ds );
        if ( ds->ds_origfilter ) {
-               dynlist_filter_free( op, op->ors_filter );
+               filter_free_x( op, op->ors_filter, 1 );
                op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
        } else {
                ds->ds_origfilter = op->ors_filter;
@@ -1994,6 +1958,8 @@ dynlist_search( Operation *op, SlapReply *rs )
                                SlapReply       r = { REP_SEARCH };
                                (void)o.o_bd->be_search( &o, &r );
                        }
+                       o.o_tmpfree( o.ors_filterstr.bv_val, o.o_tmpmemctx );
+                       o.ors_filterstr.bv_val = NULL;
                        if ( found != ds->ds_found && nested )
                                dynlist_nestlink( op, ds );
                }
index d7073d773f4ff9bb103000be5c9bdafa59b06d13..106a3710acbb4583f61cd53538043b09f6a4b9af 100644 (file)
@@ -331,6 +331,9 @@ LDAP_SLAPD_F (void) ava_free LDAP_P((
        Operation *op,
        AttributeAssertion *ava,
        int freeit ));
+LDAP_SLAPD_F (AttributeAssertion *) ava_dup LDAP_P((
+       AttributeAssertion *ava,
+       void *memctx ));
 
 /*
  * backend.c