fix: heap-use-after-free and memory leaks on erorr cases

This commit is contained in:
matteo 2026-01-30 12:21:29 +01:00 committed by Matteo Flebus
parent f0b39535fb
commit 5740195cb3
4 changed files with 18 additions and 11 deletions

View file

@ -238,16 +238,20 @@ struct ast *parse_input(struct lexer_context *ctx)
}
struct ast *ast = parse_list(ctx);
if (ast == NULL)
return NULL;
token = PEEK_TOKEN();
if (token->type == TOKEN_NEWLINE || token->type == TOKEN_EOF)
if (ast == NULL)
{
if (token->type == TOKEN_NEWLINE)
if (token != NULL && token->type == TOKEN_EOF)
{
POP_TOKEN();
}
return NULL;
}
if (token->type == TOKEN_NEWLINE || token->type == TOKEN_EOF)
{
POP_TOKEN();
return ast;
}