Skip to content

Commit

Permalink
Ensure the comment and diagnostic lists are fully freed
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Feb 21, 2023
1 parent bc256be commit ab0ce1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/diagnostic.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ yp_diagnostic_list_append(yp_list_t *list, const char *message, uint32_t positio
// Deallocate the internal state of the given diagnostic list.
void
yp_diagnostic_list_free(yp_list_t *list) {
yp_list_node_t *node = list->head;
yp_list_node_t *next;
yp_list_node_t *node, *next;

while (node != NULL) {
for (node = list->head; node != NULL; node = next) {
next = node->next;
yp_string_free(&((yp_diagnostic_t *) node)->message);
free(node);
node = next;

yp_diagnostic_t *diagnostic = (yp_diagnostic_t *) node;
yp_string_free(&diagnostic->message);

free(diagnostic);
}
}
15 changes: 14 additions & 1 deletion src/yarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6426,12 +6426,25 @@ yp_parser_register_encoding_decode_callback(yp_parser_t *parser, yp_encoding_dec
parser->encoding_decode_callback = callback;
}

// Free all of the memory associated with the comment list.
static inline void
yp_comment_list_free(yp_list_t *list) {
yp_list_node_t *node, *next;

for (node = list->head; node != NULL; node = next) {
next = node->next;

yp_comment_t *comment = (yp_comment_t *) node;
free(comment);
}
}

// Free any memory associated with the given parser.
__attribute__((__visibility__("default"))) extern void
yp_parser_free(yp_parser_t *parser) {
yp_diagnostic_list_free(&parser->error_list);
yp_diagnostic_list_free(&parser->warning_list);
yp_list_free(&parser->comment_list);
yp_comment_list_free(&parser->comment_list);
}

// Get the next token type and set its value on the current pointer.
Expand Down

0 comments on commit ab0ce1f

Please sign in to comment.