From d405b8cd57708b5b097b57e4e44cb849dfd7b399 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 1 Jan 2020 11:57:06 -0600 Subject: If allocation update is done in blocks, initial allocation has to populate a full block. --- toys/pending/sh.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'toys') diff --git a/toys/pending/sh.c b/toys/pending/sh.c index d575791f..300ad24b 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -287,10 +287,11 @@ static char *expand_one_arg(char *new, unsigned flags, struct string_list **del) memset(&arg, 0, sizeof(arg)); expand_arg(&arg, new, flags, 0); - if (arg.c == 1) s = *arg.v; - else for (i = 0; i < arg.c; i++) free(arg.v[i]); + if (arg.c == 1) { + s = *arg.v; + if (del && s != new) dlist_add((void *)del, s); + } else for (i = 0; i < arg.c; i++) free(arg.v[i]); free(arg.v); - if (del && s != new) dlist_add((void *)del, s); return s; } @@ -722,7 +723,7 @@ if (BUGBUG) { int i; dprintf(255, "envlen=%d arg->c=%d run=", envlen, arg->c); f if (envlen) { kk = 0; if (environ) while (environ[kk]) kk++; - if (kk) env = xmemdup(environ, sizeof(char *)*(kk+1)); + if (kk) env = xmemdup(environ, sizeof(char *)*(kk+33)); for (j = 0; jv[j], NO_PATH|NO_SPLIT, &pp->delete); for (ll = 0; lltype, pl->arg->v[0], pl->arg->v[ pl = blk->end; // TODO collate end_block logic - // if ending a block, free, cleanup redirects, and pop stack. - + // if ending a block, free, cleanup redirects and pop stack. llist_traverse(blk->fdelete, free); unredirect(blk->urd); if (*pipes) close(*pipes); -- cgit v1.2.3