From 943848cb0233b15f8a9e1eb6d20c078b0c919dc9 Mon Sep 17 00:00:00 2001 From: Luis Ontanon Date: Thu, 9 Mar 2006 00:50:05 +0000 Subject: Actually fix that leak! svn path=/trunk/; revision=17540 --- tools/lemon/lemon.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 43e68b146e..db2e3d5e16 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -2649,16 +2649,17 @@ PRIVATE void tplt_xfer(const char *name, FILE *in, FILE *out, int *lineno) PRIVATE FILE *tplt_open(struct lemon *lemp) { static char templatename[] = "lempar.c"; - char buf[1000]; + char* buf; FILE *in; char *tpltname = NULL; char *cp; if (lemp->templatename) { - tpltname = lemp->templatename; + tpltname = strdup(lemp->templatename); } else { cp = strrchr(lemp->filename,'.'); + buf = malloc(1000); if( cp ){ sprintf(buf,"%.*s.lt",(int)(cp - lemp->filename),lemp->filename); }else{ @@ -2668,21 +2669,25 @@ PRIVATE FILE *tplt_open(struct lemon *lemp) tpltname = buf; }else{ tpltname = pathsearch(lemp->argv0,templatename,0); + free(buf); } } if( tpltname==0 ){ fprintf(stderr,"Can't find the parser driver template file \"%s\".\n", templatename); lemp->errorcnt++; + free(tpltname); return 0; } in = fopen(tpltname,"r"); + free(tpltname); + if( in==0 ){ fprintf(stderr,"Can't open the template file \"%s\".\n",templatename); lemp->errorcnt++; - return 0; + return 0; } - if (tpltname) free(tpltname); + return in; } -- cgit v1.2.3