From 75c2e738c5e3ec96322b497acd4b9108543eff7f Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 3 Mar 2024 09:56:49 +0100 Subject: [PATCH] fix memory leak config read --- src/kds_s2000w_config.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/kds_s2000w_config.c b/src/kds_s2000w_config.c index 79c0d24..1894eb0 100644 --- a/src/kds_s2000w_config.c +++ b/src/kds_s2000w_config.c @@ -5,8 +5,6 @@ char* read_config_file(const char* filename) { - char* config_stream = NULL; - FILE* config_file = fopen(filename, "r"); int char_count = 0; @@ -14,10 +12,13 @@ char* read_config_file(const char* filename) while(fread(buf, sizeof(char), 1, config_file)) { char_count++; } + free(buf); + buf = NULL; fseek(config_file, 0L, SEEK_SET); - config_stream = malloc(sizeof(char) * char_count); + char* config_stream = malloc(sizeof(char) * char_count); fread(config_stream, char_count, 1, config_file); + config_stream[char_count - 1 ] = '\0'; fclose(config_file); config_file = NULL; -- 2.39.5