lang: fix a bunch of memory leaks
This commit is contained in:
@@ -39,8 +39,31 @@ enum ivy_status ivy_parser_create(struct ivy_parser **parser)
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
void ivy_parser_destroy(struct ivy_parser *parser)
|
||||
void ivy_parser_destroy(struct ivy_parser *parser, struct ivy_ast_node **result)
|
||||
{
|
||||
struct ivy_ast_node *root = NULL;
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_iterator_begin(&parser->p_state, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct parser_state *state
|
||||
= b_unbox(struct parser_state, it.entry, s_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
|
||||
if (root) {
|
||||
ivy_ast_node_destroy(root);
|
||||
}
|
||||
|
||||
root = state->s_node;
|
||||
free(state);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
*result = root;
|
||||
} else if (root) {
|
||||
ivy_ast_node_destroy(root);
|
||||
}
|
||||
|
||||
free(parser);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user