diff options
author | Rob Landley <rob@landley.net> | 2022-03-22 14:24:31 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2022-03-22 14:24:31 -0500 |
commit | 3f7ea911d886343d3f388371f6dad7572428625a (patch) | |
tree | bb3bd497742b4d0f681306faf93d6c44a7e8e4f4 | |
parent | bbe709fb879ad51fb50b845290dd787645686fda (diff) | |
download | toybox-3f7ea911d886343d3f388371f6dad7572428625a.tar.gz |
Fix a memory leak and update reference after discarding blank pipeline segment.
-rw-r--r-- | toys/pending/sh.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 85be8266..8f45c172 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -350,6 +350,7 @@ void debug_show_fds() struct dirent *DE; char *s, *ss = 0, buf[4096], *sss = buf; + if (!X) return; for (; (DE = readdir(X));) { if (atoi(DE->d_name) == fd) continue; s = xreadlink(ss = xmprintf("/proc/self/fd/%s", DE->d_name)); @@ -1547,7 +1548,7 @@ static void wildcard_add_files(struct sh_arg *arg, char *pattern, if (!dt) return arg_add(arg, pattern); while (dt) { while (dt->child) dt = dt->child; - arg_add(arg, dirtree_path(dt, 0)); + arg_add(arg, push_arg(delete, dirtree_path(dt, 0))); do { pp = (void *)dt; if ((dt = dt->parent)) dt->child = dt->child->next; @@ -2285,9 +2286,7 @@ static struct sh_process *expand_redir(struct sh_arg *arg, int skip, int *urd) for (j = skip; j<arg->c; j++) { int saveclose = 0, bad = 0; - s = arg->v[j]; - - if (!strcmp(s, "!")) { + if (!strcmp(s = arg->v[j], "!")) { pp->flags ^= PFLAG_NOT; continue; @@ -2889,8 +2888,10 @@ funky: // Stop at EOL. Discard blank pipeline segment, else end segment if (end == start) done++; - if (!pl->type && !arg->c) free_pipeline(dlist_lpop(ppl)); - else pl->count = -1; + if (!pl->type && !arg->c) { + free_pipeline(dlist_lpop(ppl)); + pl = *ppl ? (*ppl)->prev : 0; + } else pl->count = -1; continue; } |