summaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2023-01-08 15:39:19 -0800
committerPreston Pan <preston@nullring.xyz>2023-01-08 15:39:19 -0800
commit19367a27472a06634424e56c1eb21e4f53da4e9e (patch)
treefc58a08d36d451bdd1e7143a7358ac8a374355f7 /src/parser.c
parent87d82ead963c24d84a4f6e417b96b9bf73d132bb (diff)
fixed invalid read; some memory leakage fixed but not completely
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c
index 0f1ba69..dc949fe 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -7,6 +7,14 @@
#include <stdlib.h>
#include <string.h>
+void parser_reset(parser_t *parser, lexer_t *lexer) {
+ for (int i = 0; i < parser->size; i++) {
+ free(parser->tokens[i]);
+ }
+ parser->i = 0;
+ parser->finished = false;
+}
+
parser_t *init_parser_copy_hash(lexer_t *lexer, hash_table_t *h) {
parser_t *p = (parser_t *)malloc(sizeof(parser_t));
if (p == NULL)
@@ -203,6 +211,10 @@ ast_t *parse_include(parser_t *parser) {
if (parser->tokens[parser->i]->type != TOKEN_RPAREN)
parser_error(parser);
parser_move(parser);
+
+ free(lexer);
+ free(buffer);
+ parser_free(p);
return root;
} else {
parser_error(parser);
@@ -317,3 +329,11 @@ void parser_error(parser_t *parser) {
printf("PARSER ERROR: something went wrong.\n");
exit(1);
}
+
+void parser_free(parser_t *parser) {
+ for (int i = 0; i < parser->size; i++) {
+ free(parser->tokens[i]);
+ }
+ free(parser->tokens);
+ free(parser);
+}