From cc25563cd2f46e7c1c8cf5edd5215948cc13f19d Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Wed, 29 Apr 2026 19:23:59 +0200 Subject: [PATCH] Cleanup --- v0/ast.h | 6 +++--- v0/parser.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/v0/ast.h b/v0/ast.h index 069298d..69e01f5 100644 --- a/v0/ast.h +++ b/v0/ast.h @@ -11,7 +11,7 @@ typedef struct { /** @brief The name of the module being imported. */ - const char* module_name; + char* module_name; /** @brief Whether the import is public or not. */ bool is_public; @@ -53,7 +53,7 @@ struct TypeExpression{ */ typedef struct { /** @brief The name of the alias. */ - const char* name; + char* name; /** @brief The value of the alias. */ TypeExpression value; @@ -68,7 +68,7 @@ typedef struct { */ typedef struct { /** @brief The name of the module. */ - const char* name; + char* name; /** @brief The list of imports in the module. */ ImportDeclaration* imports; diff --git a/v0/parser.c b/v0/parser.c index 1eddb18..157d892 100644 --- a/v0/parser.c +++ b/v0/parser.c @@ -224,6 +224,7 @@ Module* parser_parse(TokenStream* ts) { parser_next_token(p); Module* module = malloc(sizeof(Module)); + memset(module, 0, sizeof(Module)); if (!parse_declaration_module(p, module)) { goto fail; } @@ -265,20 +266,25 @@ void free_type_expression(TypeExpression* expr) { } void parser_free(Module* module) { - if (module == NULL) return; + if (module == NULL) { + return; + } + if (module->imports != NULL) { for(size_t i = 0; i < module->import_count; i++) { - free((void*)module->imports[i].module_name); + free(module->imports[i].module_name); } free(module->imports); } + if (module->aliases != NULL) { for(size_t i = 0; i < module->alias_count; i++) { - free((void*)module->aliases[i].name); + free(module->aliases[i].name); free_type_expression(&module->aliases[i].value); } free(module->aliases); } - free((void*)module->name); + + free(module->name); free(module); }