lemon auto-frees only tokens and nodes that are not referenced in
the rule's action. Since most of these are malloc'ed containers
from which we only use some of the content, we need to explicitly
free them.
---
 src/compiler/parser.y |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/compiler/parser.y b/src/compiler/parser.y
index 62409f3..40157c2 100644
--- a/src/compiler/parser.y
+++ b/src/compiler/parser.y
@@ -121,6 +121,7 @@ assignments ::= .
 
 assignment ::= ident(I) TOK_ASSIGN node(N) opt_semi. {
        state->error = state->comm->assign_default(state->comm, I->label, N);
+       free(I);
        if(state->error) {
                syntax_error(state);
                yy_parse_failed(yypParser);
@@ -132,11 +133,16 @@ assignment ::= ident(I) TOK_ASSIGN node(N) opt_semi. {
 assignment ::= TOK_IMAGEFILE(I) TOK_ASSIGN TOK_FNAME(N). {
        state->error = state->comm->assign_image_name(state->comm,
            atoi(I->label+9), N->label);
+       free(I);
        if(state->error) {
                syntax_error(state);
                yy_parse_failed(yypParser);
+               free((void *) N->label);
+               free(N);
                return;
        }
+       free((void *) N->label);
+       free(N);
 }
 
 assignment ::= context(C). {
@@ -171,10 +177,12 @@ opt_semi ::= .
 node(N) ::= TOK_CONSTANT(C). {
        N = node(TOK_CONSTANT, "", NULL, NULL, NULL);
        N->contents.constant = C->constant;
+       free(C);
 }
 
 node(N) ::= ident(I). {
        N = node(I->token, I->label, NULL, NULL, NULL);
+       free(I);
 }
 
 %left TOK_PLUS TOK_MINUS.
@@ -207,15 +215,18 @@ node(N) ::= TOK_MINUS node(A). [TOK_NOT] {
 
 node(N) ::= unary(I) TOK_LPAREN node(A) TOK_RPAREN. {
        N = node(I->token, I->label, A, NULL, NULL);
+       free(I);
 }
 
 node(N) ::= binary(I) TOK_LPAREN node(A) TOK_COMMA node(B) TOK_RPAREN. {
        N = node(I->token, I->label, A, B, NULL);
+       free(I);
 }
 
 node(N) ::= ternary(I) TOK_LPAREN node(A) TOK_COMMA node(B) TOK_COMMA node(C)
     TOK_RPAREN. {
        N = node(I->token, I->label, A, B, C);
+       free(I);
 }
 
 node(N) ::= TOK_LPAREN node(A) TOK_RPAREN. {
-- 
1.7.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to