From 170e69d096a9409122e6f90d64e66e4c60ad9865 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Fri, 9 Feb 2024 15:31:30 +0100 Subject: [PATCH 1/2] free line if getline errors --- modfetch.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modfetch.c b/modfetch.c index 68b0da9..fd24bdd 100644 --- a/modfetch.c +++ b/modfetch.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -140,6 +141,9 @@ Config parse_config(FILE *config_file) { .module_count = 0, }; + // TODO handle errors of all the function inside the while + errno = 0; + // TODO rewrite this to read the config char by char while ((read = getline(&line, &len, config_file)) != -1) { if (read <= 1) @@ -200,6 +204,8 @@ Config parse_config(FILE *config_file) { free(line); } + if (read == -1 && errno != 0) + free(line); return config; } From 9ac418318a9a07ca3d0f628626c5b798276cc31e Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Fri, 9 Feb 2024 15:34:15 +0100 Subject: [PATCH 2/2] nullterm ret in resolve_env_vars --- modfetch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/modfetch.c b/modfetch.c index fd24bdd..dfd6d3e 100644 --- a/modfetch.c +++ b/modfetch.c @@ -110,6 +110,7 @@ char *resolve_env_vars(const char *str) { ret[ret_offset] = str[i]; ret_offset += 1; } + ret[ret_offset] = '\0'; return ret; }