From 24a096fb27eb0959366c605499c7819352cc501c Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Thu, 30 Apr 2015 12:44:19 +0200 Subject: [PATCH] - Plug some lemon leaks during xlat generation. Found with Address Sanitizer. --- tools/lemon/lemon.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index f4a08f7894..5e8f03a8bc 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -437,7 +437,8 @@ struct acttab { #define acttab_yylookahead(X,N) ((X)->aAction[N].lookahead) /* Free all memory associated with the given acttab */ -void acttab_free(acttab *p){ +void acttab_free(acttab **pp){ + acttab *p = *pp; free( p->aAction ); free( p->aLookahead ); free( p ); @@ -2506,12 +2507,14 @@ struct lemon *gp; ErrorMsg(ps.filename,0,"Can't allocate %d of memory to hold this file.", filesize+1); gp->errorcnt++; + fclose(fp); return; } if( fread(filebuf,1,filesize,fp)!=filesize ){ ErrorMsg(ps.filename,0,"Can't read in all %d bytes of this file.", filesize); free(filebuf); + fclose(fp); gp->errorcnt++; return; } @@ -3081,9 +3084,11 @@ struct lemon *lemp; in = fopen(tpltname,"rb"); if( in==0 ){ fprintf(stderr,"Can't open the template file \"%s\".\n",templatename); + free(tpltname); lemp->errorcnt++; return 0; } + free(tpltname); return in; } @@ -3942,6 +3947,7 @@ int mhflag; /* Output in makeheaders format if true */ /* Append any addition code the user desires */ tplt_print(out,lemp,lemp->extracode,lemp->extracodeln,&lineno); + acttab_free(&pActtab); fclose(in); fclose(out); return;