summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Maniero <carlos@maniero.me>2023-05-02 23:45:57 -0300
committerJohnny Richard <johnny@johnnyrichard.com>2023-05-03 23:01:24 +0200
commit7aebc787c5529997e422a054398ed739ca4cddfe (patch)
treedea448248b789675245925c8f7c5318839de1aeb
parent0b0ce0d1735b4358691fb1d4a85b550d45ae9d48 (diff)
parser: Fixes block parser memory leak
When a error occurs during a block parser the vector that stores the nodes had been destroyed but it's nodes don't. This commit fixes this by replacing the %vector_destroy% with %ast_node_destroy_vector%. Signed-off-by: Carlos Maniero <carlos@maniero.me>
-rw-r--r--src/ast.c2
-rw-r--r--src/ast.h4
-rw-r--r--src/parser.c8
3 files changed, 9 insertions, 5 deletions
diff --git a/src/ast.c b/src/ast.c
index bac4021..5938e1d 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -31,7 +31,7 @@ ast_node_new(void)
return node;
}
-static void
+void
ast_node_destroy_vector(vector_t *vector)
{
for (size_t i = 0; i < vector->size; i++) {
diff --git a/src/ast.h b/src/ast.h
index e541390..bdace51 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -124,6 +124,10 @@ typedef struct ast_node_t
ast_node_t *
ast_node_new(void);
+
+void
+ast_node_destroy_vector(vector_t *vector);
+
void
ast_node_destroy(ast_node_t *node);
diff --git a/src/parser.c b/src/parser.c
index f51f550..82d25f5 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -431,7 +431,7 @@ parser_parse_block_declarations(parser_t *parser)
if (return_node == NULL) {
scope_leave(parser->scope);
- vector_destroy(body);
+ ast_node_destroy_vector(body);
return NULL;
}
@@ -444,7 +444,7 @@ parser_parse_block_declarations(parser_t *parser)
if (variable_node == NULL) {
scope_leave(parser->scope);
- vector_destroy(body);
+ ast_node_destroy_vector(body);
return NULL;
}
@@ -457,7 +457,7 @@ parser_parse_block_declarations(parser_t *parser)
if (variable_assignment == NULL) {
scope_leave(parser->scope);
- vector_destroy(body);
+ ast_node_destroy_vector(body);
return NULL;
}
@@ -468,7 +468,7 @@ parser_parse_block_declarations(parser_t *parser)
parser_error_report_unexpected_token(parser);
scope_leave(parser->scope);
- vector_destroy(body);
+ ast_node_destroy_vector(body);
return NULL;
}