shithub: scc

Download patch

ref: e2295568f7a70f6db3359ef3db8719ec26544ffb
parent: 411c5618c377b28556835dcb7ad756b6072644e4
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 14 10:55:38 EDT 2015

Free memory reserved for strings

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -138,7 +138,8 @@
 	ISPRIVATE  =     256,
 	ISLOCAL    =     512,
 	ISEMITTED  =    1024,
-	ISDEFINED  =    2048
+	ISDEFINED  =    2048,
+	ISSTRING   =    4096
 };
 
 
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -359,7 +359,7 @@
 
 	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++ = '"';
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -130,7 +130,8 @@
 				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;