Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
command substitution
memory leaks (rhbz#982142)
This fixes two memory leaks in old-style command substitutions (one when invoking an alias, one when invoking an autoloaded function), as well as a possible third leak with an unknown reproducer, by applying this Red Hat patch: https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-mlikfiks.patch src/cmd/ksh93/sh/macro.c: comsubst(): - For as-yet unknown reasons, the alias leak did not occur when adding a space at the end of the command substitution, as in a=`some_alias `. This fix is a workaround that simply writes an extra space to the stack. TODO: a real fix. src/cmd/ksh93/sh/path.c: funload(): - Add missing free() before return. This fixes the leak with autoloaded functions. src/cmd/ksh93/sh/lex.c: alias_exceptf(): - This function is called "whenever an end of string is found with alias". This adds a check for an SF_FINAL stream status flag when deciding whether to call free(). In sfio.h this is commented as: #define SF_FINAL 11 /* closing is done except stream free */ When I revert this change, none of the regression tests fail, so I don't know how to trigger this supposed leak. But it makes some sense given the sfio.h comment, so I'll keep it. src/cmd/ksh93/tests/leaks.sh: - Add the reproducers from rhbz#982142 as regression tests (including an extra one for nested command substitutions that was already fixed as of 93u+, but testing is good). I replaced the external 'expr' and 'ls' commands by uses of the 'true' builtin, otherwise the tests take far too long to run with 16384 iterations. At least the alias leak was still behaving identically after replacing 'ls' by 'true'.
- Loading branch information
fe20311
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have found an email on the old mailing list with a different fix for the memory leak in macro.c: https://www.mail-archive.com/ast-developers@lists.research.att.com/msg01889.html
The patch in the email could replace the hack fix for
a=some_alias
. I tested it and all the regression tests pass when the email's patch is used instead.fe20311
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointer.
Unfortunately, when I replace the change in macro.c from this commit with the patch from that email, I do get a leak regression:fe20311
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have done something wrong. I tried the fix from the mailing list again and the leak is gone.
I still don't like it, though. It's just as hackish as the Red Hat one.
And in fact it does now (somehow) cause one regression, of a test recently added:
The real fix to figure out is how to actually throw a syntax error on something like
echo `"ls foo`
. It's bogus and the parser shouldn't accept it.