Skip to content

Commit

Permalink
Merge pull request #77 from Brainrotlang/feat/array_expression
Browse files Browse the repository at this point in the history
fix(array): memory leaks in ExpressionList
  • Loading branch information
araujo88 authored Jan 16, 2025
2 parents 2e31f28 + 2a5c870 commit 18f2d8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2926,12 +2926,16 @@ size_t count_expression_list(ExpressionList* list)

void free_expression_list(ExpressionList* list)
{
while (list)
if (!list)
return;
ExpressionList* current = list->next;
while (current != list)
{
ExpressionList* next = list->next;
free(list);
list = next;
ExpressionList* next = current->next;
free(current);
current = next;
}
free(list);
}

void populate_array_varialbe(char* name, ExpressionList* list)
Expand Down
2 changes: 2 additions & 0 deletions lang.y
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,14 @@ declaration:
set_array_variable($3, count_expression_list($7), get_current_modifiers(), $2);
populate_array_varialbe($3, $7);
$$ = create_array_declaration_node($3, count_expression_list($7), $2);
free_expression_list($7);
}
| optional_modifiers type IDENTIFIER LBRACKET INT_LITERAL RBRACKET EQUALS array_init
{
set_array_variable($3, $5, get_current_modifiers(), $2);
populate_array_varialbe($3, $8);
$$ = create_array_declaration_node($3, $5, $2);
free_expression_list($8);
}
;

Expand Down

0 comments on commit 18f2d8d

Please sign in to comment.