scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit e2295568f7a70f6db3359ef3db8719ec26544ffb
parent 411c5618c377b28556835dcb7ad756b6072644e4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 14 Aug 2015 14:55:38 +0200

Free memory reserved for strings

Diffstat:
Mcc1/cc1.h | 3++-
Mcc1/lex.c | 2+-
Mcc1/symbol.c | 3++-
3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -138,7 +138,8 @@ enum { ISPRIVATE = 256, ISLOCAL = 512, ISEMITTED = 1024, - ISDEFINED = 2048 + ISDEFINED = 2048, + ISSTRING = 4096 }; diff --git a/cc1/lex.c b/cc1/lex.c @@ -359,7 +359,7 @@ repeat: yylen = bp - yytext + 1; yylval.sym = newsym(NS_IDEN); - yylval.sym->flags |= ISCONSTANT; + yylval.sym->flags |= ISSTRING | ISCONSTANT; yylval.sym->u.s = xstrdup(yytext+1); yylval.sym->type = mktype(chartype, ARY, yylen - 2, NULL); *bp++ = '"'; diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -130,7 +130,8 @@ popctx(void) warn("'%s' defined but not used", sym->name); } free(sym->name); - // TODO: There is a memory leak with sym->u.s + if (sym->flags & ISSTRING) + free(sym->u.s); free(sym); } head = sym;