1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +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:
  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:
Martijn Dekker 2020-09-15 07:47:38 +02:00
parent 16e4824c45
commit 05683ec75b
3 changed files with 42 additions and 1 deletions

View file

@ -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))