ITS#9929 plug memleaks

This commit is contained in:
Howard Chu 2022-11-30 19:28:04 +00:00 committed by Quanah Gibson-Mount
parent 00610ee886
commit c8e039aa15
5 changed files with 37 additions and 56 deletions

View 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,

View 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:

View 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 );

View 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 );
}

View 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