From 19367a27472a06634424e56c1eb21e4f53da4e9e Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Sun, 8 Jan 2023 15:39:19 -0800 Subject: fixed invalid read; some memory leakage fixed but not completely --- src/visitor.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/visitor.c') diff --git a/src/visitor.c b/src/visitor.c index 65af934..bcea8e4 100644 --- a/src/visitor.c +++ b/src/visitor.c @@ -8,6 +8,8 @@ #include #include +void visitor_reset() {} + visitor_t *init_visitor(parser_t *p) { visitor_t *v = (visitor_t *)malloc(sizeof(visitor_t)); if (v == NULL) @@ -535,8 +537,8 @@ ast_t *eval_list(visitor_t *v, ast_t *e) { } stack_push(v->stack_frame, stack_frame); ast_t *res = eval_expr(v, function->cdr); - stack_frame = stack_pop(v->stack_frame); - /* hash_table_free(stack_frame); */ + stack_pop(v->stack_frame); + hash_table_free_some(stack_frame); return res; } @@ -572,3 +574,10 @@ void eval_error(visitor_t *v, ast_t *e) { printf("ERROR: something went wrong with the visitor.\n"); exit(1); } + +void visitor_free(visitor_t *v) { + ast_free(v->root); + hash_table_free(v->eval_table); + stack_free(v->stack_frame); + free(v); +} -- cgit