[hackers] [scc] Free memory reserved for strings || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 14 Aug 2015 17:08:59 +0200 (CEST)

commit e2295568f7a70f6db3359ef3db8719ec26544ffb
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Aug 14 14:55:38 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Aug 14 14:55:38 2015 +0200

    Free memory reserved for strings

diff --git a/cc1/cc1.h b/cc1/cc1.h
index f9ed793..094f358 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -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
index 507379e..34bccb1 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -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
index e67784d..f780281 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -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;
Received on Fri Aug 14 2015 - 17:08:59 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 14 2015 - 17:12:16 CEST