From d453a572efce146f3dd6a4884b1d2d3384fd7a4a Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 9 Dec 2015 15:06:19 +0000 Subject: [PATCH 1/3] - make backeval use its own paraml - introduce initlex() and call freelex() before calling lex() --- Fixes | 1 + sh.c | 2 ++ sh.decls.h | 1 + sh.exp.c | 1 + sh.glob.c | 14 +++++++++----- sh.lex.c | 7 +++++++ 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Fixes b/Fixes index 689aeb0..1fe33e8 100644 --- a/Fixes +++ b/Fixes @@ -1,3 +1,4 @@ + 9. Fix memory leak for paraml 8. Add notempty and ask values for the noclobber setting (Martin Tournoij) 7. more correct $wordchars for vimode (Luke Mewburn) 6. expose VImode in $vimode (Luke Mewburn) diff --git a/sh.c b/sh.c index 8d219d3..c6a0bfe 100644 --- a/sh.c +++ b/sh.c @@ -274,6 +274,7 @@ main(int argc, char **argv) #endif nlsinit(); + initlex(¶ml); #ifdef MALLOC_TRACE mal_setstatsfile(fdopen(dmove(xopen("/tmp/tcsh.trace", @@ -2049,6 +2050,7 @@ process(int catch) */ if (setintr) pintr_push_enable(&old_pintr_disabled); + freelex(¶ml); hadhist = lex(¶ml); if (setintr) cleanup_until(&old_pintr_disabled); diff --git a/sh.decls.h b/sh.decls.h index 671a0b7..09ac3ab 100644 --- a/sh.decls.h +++ b/sh.decls.h @@ -239,6 +239,7 @@ extern void btell (struct Ain *); extern void btoeof (void); extern void copylex (struct wordent *, struct wordent *); extern Char *domod (Char *, Char); +extern void initlex (struct wordent *); extern void freelex (struct wordent *); extern int lex (struct wordent *); extern void lex_cleanup (void *); diff --git a/sh.exp.c b/sh.exp.c index 7e75a45..cf7f69b 100644 --- a/sh.exp.c +++ b/sh.exp.c @@ -968,6 +968,7 @@ evalav(Char **v) } hp->prev = wdp; cleanup_push(¶ml1, lex_cleanup); + initlex(¶ml1); alias(¶ml1); t = syntax(paraml1.next, ¶ml1, 0); cleanup_push(t, syntax_cleanup); diff --git a/sh.glob.c b/sh.glob.c index 7d008aa..dce0217 100644 --- a/sh.glob.c +++ b/sh.glob.c @@ -765,6 +765,9 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) omark = cleanup_push_mark(); getexit(osetexit); for (;;) { + struct wordent paraml1; + initlex(¶ml1); + (void) setexit(); justpr = 0; @@ -780,12 +783,13 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) seterr = NULL; } - (void) lex(¶ml); - cleanup_push(¶ml, lex_cleanup); + freelex(¶ml1); + (void) lex(¶ml1); + cleanup_push(¶ml1, lex_cleanup); if (seterr) stderror(ERR_OLD); - alias(¶ml); - t = syntax(paraml.next, ¶ml, 0); + alias(¶ml1); + t = syntax(paraml1.next, ¶ml1, 0); cleanup_push(t, syntax_cleanup); /* The F_BACKQ flag must set so the job output is correct if * printexitvalue is set. If it's not set, the job output @@ -805,7 +809,7 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) #endif execute(t, -1, NULL, NULL, TRUE); - cleanup_until(¶ml); + cleanup_until(¶ml1); } } cleanup_until(&pvec[1]); diff --git a/sh.lex.c b/sh.lex.c index 08520dd..a64c812 100644 --- a/sh.lex.c +++ b/sh.lex.c @@ -258,6 +258,13 @@ copylex(struct wordent *hp, struct wordent *fp) } void +initlex(struct wordent *vp) +{ + vp->prev = vp; + vp->next = vp; +} + +void freelex(struct wordent *vp) { struct wordent *fp; -- 2.5.5 From 5298f499085f3863b37302290eb7f794acdade6b Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 9 Dec 2015 17:17:43 +0000 Subject: [PATCH 2/3] Call initlex() sooner, instead of hand-crafted code. --- sh.exp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sh.exp.c b/sh.exp.c index cf7f69b..8838fce 100644 --- a/sh.exp.c +++ b/sh.exp.c @@ -955,8 +955,7 @@ evalav(Char **v) struct wordent *wdp = hp; setcopy(STRstatus, STR0, VAR_READWRITE); - hp->prev = hp->next = hp; - hp->word = STRNULL; + initlex(hp); while (*v) { struct wordent *new = xcalloc(1, sizeof *wdp); @@ -968,7 +967,6 @@ evalav(Char **v) } hp->prev = wdp; cleanup_push(¶ml1, lex_cleanup); - initlex(¶ml1); alias(¶ml1); t = syntax(paraml1.next, ¶ml1, 0); cleanup_push(t, syntax_cleanup); -- 2.5.5 From aaf05158924cde1f78d31c67671c38b9f2e8e850 Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 9 Dec 2015 17:17:55 +0000 Subject: [PATCH 3/3] Initialize word in initlex() --- sh.lex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sh.lex.c b/sh.lex.c index a64c812..8a6d1b0 100644 --- a/sh.lex.c +++ b/sh.lex.c @@ -260,6 +260,7 @@ copylex(struct wordent *hp, struct wordent *fp) void initlex(struct wordent *vp) { + vp->word = STRNULL; vp->prev = vp; vp->next = vp; } -- 2.5.5