From: Mart Lubbers Date: Mon, 8 Feb 2021 10:06:14 +0000 (+0100) Subject: fix minor memory leak X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=a77534a15bddba94523ed0fe4ea278494372a69b;p=ccc.git fix minor memory leak --- diff --git a/ast.c b/ast.c index f7748f6..622ba74 100644 --- a/ast.c +++ b/ast.c @@ -22,11 +22,6 @@ struct ast *ast(struct list *decls) return res; } -struct vardecl vardecl(char *ident, struct expr *expr) -{ - return (struct vardecl) {.ident=ident, .expr=expr}; -} - struct decl *decl_fun(char *ident, struct list *args, struct list *body) { struct decl *res = safe_malloc(sizeof(struct decl)); @@ -399,6 +394,7 @@ void ast_free(struct ast *ast) return; for (int i = 0; indecls; i++) decl_free(ast->decls[i]); + free(ast->decls); free(ast); } diff --git a/ast.h b/ast.h index a001757..6b8f427 100644 --- a/ast.h +++ b/ast.h @@ -96,8 +96,6 @@ struct expr { struct ast *ast(struct list *decls); -struct vardecl vardecl(char *ident, struct expr *expr); - struct decl *decl_fun(char *ident, struct list *args, struct list *body); struct decl *decl_var(struct vardecl vardecl); diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..44ec6ef --- /dev/null +++ b/input.txt @@ -0,0 +1,12 @@ +var x = 5 == 5; +var y = x; +fun(x){ + var x = 5; + 6; + if(true){5;}else{5;} + '\t'; +return 5; +f(); +f(x); f(1, 2, []); +y = 5+x.fst.snd; +} diff --git a/parse.y b/parse.y index 3cc1d44..33e9881 100644 --- a/parse.y +++ b/parse.y @@ -64,7 +64,7 @@ decls | decls fundecl { $$ = list_cons($2, $1); } ; vardecl - : VAR IDENT ASSIGN expr { $$ = vardecl($2, $4); } + : VAR IDENT ASSIGN expr { $$ = (struct vardecl) {.ident=$2, .expr=$4}; } ; fundecl : IDENT BOPEN args BCLOSE COPEN body CCLOSE