Skip to content

Commit

Permalink
Fix leak when unsetting PATH in main shell
Browse files Browse the repository at this point in the history
src/cmd/ksh93/sh/path.c:
- Stop calling path_dup() on defpathinit() return value as it
  immediately raises the reference count of the path components to 2
  and makes it such that a single path_delete() is not sufficient for
  freeing the path components. The path_dup() call in path_addpath()
  which caused the leak was last strictly necessary probably in ksh93o.

Progresses: ksh93#405
  • Loading branch information
atheik committed Jun 20, 2022
1 parent bf34bbb commit 4ad49ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/cmd/ksh93/sh/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ static void pathinit(void)
}
else
{
pp = defpathinit();
sh.pathlist = (void*)path_dup(pp);
sh.pathlist = pp = (void*)defpathinit();
}
if(val=sh_scoped((FPATHNOD))->nvalue.cp)
{
Expand Down Expand Up @@ -1629,7 +1628,7 @@ Pathcomp_t *path_addpath(Pathcomp_t *first, register const char *path,int type)
if(old)
{
if(!first && !path)
first = path_dup(defpathinit());
first = (void*)defpathinit();
if(cp=(sh_scoped(FPATHNOD))->nvalue.cp)
first = (void*)path_addpath((Pathcomp_t*)first,cp,PATH_FPATH);
path_delete(old);
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 @@ -360,7 +360,7 @@ DO
hash "${random_utils[@]}"
DONE

TEST title='unset PATH in main shell' known=y url=https://github.com/ksh93/ksh/issues/405
TEST title='unset PATH in main shell'
DO
unset PATH
PATH=$save_PATH
Expand Down

0 comments on commit 4ad49ed

Please sign in to comment.