free(b->contents);
free(b->name);
TAILQ_REMOVE(&blocks_head, b, blocks);
+ free(b);
+}
+
+void free_arg(struct croma_block *b, struct croma_arg *a)
+{
+ if (b == NULL)
+ return;
+
+ TAILQ_REMOVE(&b->args_head, a, params);
+ free(a->name);
+ free(a->value);
+ free(a);
}
};
/*
- blocks_head is our symbol tab.
+ blocks_head is our symbol table.
*/
TAILQ_HEAD(croma_blocks_head, croma_block) blocks_head;
struct croma_block* alloc_and_insert_block(void);
struct croma_arg *alloc_and_insert_arg(struct croma_block *b);
void free_block(struct croma_block *b);
+void free_arg(struct croma_block *b, struct croma_arg *a);
#endif
void foreach_expr(void)
{
- struct croma_block *b = malloc(sizeof(struct croma_block));
-
- if (b == NULL)
- fail("Unable to alloc() memory");
+ struct croma_block *b = alloc_and_insert_block();
TAILQ_INIT(&b->args_head);
expect(LPAREN);
c++;
}
+ free_arg(b, a);
}
free_block(b);
arg->value = strdup(yytext);
if (arg->value == NULL)
fail("Unable to allocate memory");
-
- continue;
break;
case RPAREN: