mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 19:52:20 +00:00
Fix several memory leaks related to arrays (rhbz#921455)
I now have access to some of the private bugs on the Red Hat bug tracker. This one doesn't have a lot of information on the patch, but it contains a good reproducer, so we can at least verify that it works. src/cmd/ksh93/sh/array.c, src/cmd/ksh93/sh/name.c: - Apply the patch associated with Red Hat bug #921455. Source: https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-memlik.patch This was applied to Red Hat's ksh on 04 Jul 2013. src/cmd/ksh93/tests/leaks.sh: - Add leak tests for associative and indexed arrays in functions based on the reproducer from rhbz#921455. - Both tests still leak (though much less) when run in a locale other than C. For now, temporarily set the locale to C and add a TODO note. Perhaps another Red Hat patch is yet to fix this.
This commit is contained in:
parent
16e4824c45
commit
05683ec75b
3 changed files with 42 additions and 1 deletions
|
@ -1685,7 +1685,11 @@ void *nv_associative(register Namval_t *np,const char *sp,int mode)
|
|||
ap->header.scope = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((ap->header.nelem&ARRAY_MASK)==0 && (ap->cur=nv_search("0",ap->header.table,0)))
|
||||
nv_associative(np,(char*)0,NV_ADELETE);
|
||||
dtclose(ap->header.table);
|
||||
}
|
||||
return((void*)ap);
|
||||
case NV_ANEXT:
|
||||
if(!ap->pos)
|
||||
|
|
|
@ -2404,6 +2404,8 @@ static void table_unset(Shell_t *shp, register Dt_t *root, int flags, Dt_t *oroo
|
|||
}
|
||||
}
|
||||
npnext = (Namval_t*)dtnext(root,np);
|
||||
if(nv_arrayptr(np))
|
||||
nv_putsub(np,NIL(char*),ARRAY_SCAN);
|
||||
_nv_unset(np,flags);
|
||||
nv_delete(np,root,0);
|
||||
}
|
||||
|
@ -3256,7 +3258,7 @@ int nv_rename(register Namval_t *np, int flags)
|
|||
shp->last_root = last_root;
|
||||
if(flags&NV_MOVE)
|
||||
{
|
||||
if(arraynp && !nv_isattr(np,NV_MINIMAL) && (mp=(Namval_t*)np->nvenv) && (ap=nv_arrayptr(mp)))
|
||||
if(arraynp && !nv_isattr(np,NV_MINIMAL) && (mp=(Namval_t*)np->nvenv) && (ap=nv_arrayptr(mp)) && !ap->fun)
|
||||
ap->nelem++;
|
||||
}
|
||||
if((nv_arrayptr(nr) && !arraynr) || nv_isvtree(nr))
|
||||
|
|
|
@ -193,5 +193,40 @@ done
|
|||
after=$(getmem)
|
||||
err_exit_if_leak 'script sourced in virtual subshell'
|
||||
|
||||
# ======
|
||||
# Multiple leaks when using arrays in functions (Red Hat #921455)
|
||||
# Fix based on: https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-memlik.patch
|
||||
|
||||
# TODO: both of these tests still leak (although much less after the patch) when run in a non-C locale.
|
||||
saveLANG=$LANG; LANG=C # comment out to test remaining leak (1/2)
|
||||
|
||||
function _hash
|
||||
{
|
||||
typeset w=([abc]=1 [def]=31534 [xyz]=42)
|
||||
print -u2 $w 2>&-
|
||||
# accessing the var will leak
|
||||
}
|
||||
before=$(getmem)
|
||||
for ((i=0; i < N; i++))
|
||||
do _hash
|
||||
done
|
||||
after=$(getmem)
|
||||
err_exit_if_leak 'associative array in function'
|
||||
|
||||
function _array
|
||||
{
|
||||
typeset w=(1 31534 42)
|
||||
print -u2 $w 2>&-
|
||||
# unset w will prevent leak
|
||||
}
|
||||
before=$(getmem)
|
||||
for ((i=0; i < N; i++))
|
||||
do _array
|
||||
done
|
||||
after=$(getmem)
|
||||
err_exit_if_leak 'indexed array in function'
|
||||
|
||||
LANG=$saveLANG # comment out to test remaining leak (2/2)
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Reference in a new issue