From 0982f2bf3a230b331b7838ecf0755a736b804736 Mon Sep 17 00:00:00 2001 From: "Gu://em_" Date: Thu, 20 Nov 2025 18:01:06 +0100 Subject: [PATCH] fix: small bugs in config parser and string utils --- httpd/src/config/config.c | 9 ++++++++- httpd/src/utils/string/string.c | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/httpd/src/config/config.c b/httpd/src/config/config.c index c1969b5..b0ca6b7 100644 --- a/httpd/src/config/config.c +++ b/httpd/src/config/config.c @@ -117,7 +117,7 @@ static int handle_opt(char **argv, char opt, struct config *cfg) // Default file case 'D': - cfg->servers->ip = optarg; + cfg->servers->default_file = optarg; break; // PID file @@ -167,6 +167,12 @@ static void print_arg_error(int err, char **argv, struct option options[], printf("%s: Invalid value for '--%s'\n", argv[0], options[optindex].name); break; + + default: + printf( + "%s: An unknown error happened while trying to parse arguments\n", + argv[0]); + break; } } @@ -229,6 +235,7 @@ struct config *parse_configuration(int argc, char *argv[]) void config_destroy(struct config *config) { + string_destroy(config->servers->server_name); free(config->servers); free(config); } diff --git a/httpd/src/utils/string/string.c b/httpd/src/utils/string/string.c index 342d7b2..68914b5 100644 --- a/httpd/src/utils/string/string.c +++ b/httpd/src/utils/string/string.c @@ -53,6 +53,7 @@ void string_concat_str(struct string *str, const char *to_concat, size_t size) if (new_size == 0) return; + str->size = new_size; str->data = realloc(str->data, new_size); if (str->data == NULL) return; // Handle ? @@ -65,6 +66,12 @@ void string_concat_str(struct string *str, const char *to_concat, size_t size) void string_destroy(struct string *str) { - free(str->data); - free(str); + if (str != NULL) + { + if (str->data != NULL) + { + free(str->data); + } + free(str); + } }