Skip to content

Commit

Permalink
Fix leak when setting attributes of special variables
Browse files Browse the repository at this point in the history
src/cmd/ksh93/sh/array.c:
- ???

Progresses: ksh93#405
  • Loading branch information
atheik committed Jun 20, 2022
1 parent 4ad49ed commit f7a030b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/cmd/ksh93/sh/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ static Namval_t *array_find(Namval_t *np,Namarr_t *arp, int flag)
return(up->np);
}
}
if(nv_cover(np) && np->nvalue.cp && np->nvalue.cp!=Empty && !nv_isattr(np,NV_NOFREE))
free((void*)np->nvalue.cp);
np->nvalue.cp = up->cp;
if(!up->cp)
{
Expand Down Expand Up @@ -1001,7 +1003,12 @@ Namarr_t *nv_setarray(Namval_t *np, void *(*fun)(Namval_t*,const char*,int))
{
nv_putsub(np, "0", ARRAY_ADD);
if(value)
nv_putval(np, value, 0);
{
if(nv_cover(np))
nv_putv(np, value, 0, np->nvfun);
else
nv_putval(np, value, 0);
}
else
{
Namval_t *mp = (Namval_t*)((*fun)(np,NIL(char*),NV_ACURRENT));
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/tests/leaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ DO
PATH=/dev/null command true
DONE

TEST title='set PATH attribute in main shell' known=y url=https://github.com/ksh93/ksh/issues/405
TEST title='set PATH attribute in main shell'
DO
typeset -A PATH
unset PATH
Expand Down

0 comments on commit f7a030b

Please sign in to comment.