diff --git a/src/main.c b/src/main.c index 1d9f7b2..81200c2 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,15 @@ // === Functions +/* @brief: frees the hash map. + * @return: always ERR_INPUT_PROCESSING. + */ +static int err_input(struct hash_map **vars) +{ + hash_map_free(vars); + return ERR_INPUT_PROCESSING; +} + static int main_loop(struct lexer_context *ctx, struct args_options *options, struct hash_map *vars) { @@ -49,7 +58,7 @@ static int main_loop(struct lexer_context *ctx, struct args_options *options, } if (command_ast == NULL) - return ERR_INPUT_PROCESSING; + return err_input(&vars); ast_free(&command_ast); @@ -71,7 +80,7 @@ int main(int argc, char **argv) if (return_code != 0) { print_usage(stderr, argv[0]); - return ERR_INPUT_PROCESSING; + return err_input(&vars); } // args_print(&options); @@ -86,7 +95,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Error: Failed to configure IO Backend from arguments\n"); - return ERR_INPUT_PROCESSING; + return err_input(&vars); } // Init IO Backend (with the context struct) @@ -96,10 +105,9 @@ int main(int argc, char **argv) fprintf(stderr, "Error: IO Backend initialization failed with code %d\n", return_code); - return ERR_INPUT_PROCESSING; + return err_input(&vars); } - // init lexer context struct lexer_context ctx = { 0 };