Skip to content

Commit

Permalink
Update comsub-with-alias anti-leak hack (re: fe20311)
Browse files Browse the repository at this point in the history
In the 93v- beta, they add a newline instead of a space.
This has fewer side effects as final newlines get stripped.
It's still a hack and it would still be nice to have a real fix,
but it seems even the AT&T guys couldn't come up with one.

src/cmd/ksh93/sh/macro.c:
- To somehow avoid a memory leak involving alias substitution,
  append a linefeed instead of a space to the comsub buffer.

src/cmd/ksh93/tests/subshell.sh:
- Add test for minor regression caused by the RedHat version.
  • Loading branch information
McDutchie committed Feb 18, 2021
1 parent 72968ea commit 350b52e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/macro.c
Expand Up @@ -2118,7 +2118,7 @@ static void comsubst(Mac_t *mp,register Shnode_t* t, int type)
}
sfputc(stkp,c);
}
sfputc(stkp,' '); /* rhbz#982142: a=`some_alias` leaked memory, a=`some_alias ` did not! TODO: non-hack fix */
sfputc(stkp,'\n'); /* a=`some_alias` leaked memory, a=`some_alias<LF>` did not! TODO: non-hack fix */
c = stktell(stkp);
str=stkfreeze(stkp,1);
/* disable verbose and don't save in history file */
Expand Down
10 changes: 10 additions & 0 deletions src/cmd/ksh93/tests/subshell.sh
Expand Up @@ -950,5 +950,15 @@ v=main
(v=sub; (d=${ v=shared; }; [[ $v == shared ]]) ) || err_exit "shared comsub in nested subshell wrongly scoped (2)"
[[ $v == main ]] || err_exit "shared comsub leaks out of subshell (7)"

# ======
# After the memory leak patch for rhbz#982142, this minor regression was introduced:
# if a backtick command substitution expanded an alias, an extra space was inserted.
exp='word'
alias a='print -n wo\'
got=$(eval 'echo "`a`rd"')
unalias a
[[ $got == "$exp" ]] || err_exit 'backtick comsub with alias:' \
"expected $(printf %q "$exp"), got $(printf %q "$got")"

# ======
exit $((Errors<125?Errors:125))

0 comments on commit 350b52e

Please sign in to comment.