From: Bastian Dehn Date: Sun, 3 Mar 2024 08:56:49 +0000 (+0100) Subject: fix memory leak config read X-Git-Tag: v1.0.0^2~141 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=75c2e738c5e3ec96322b497acd4b9108543eff7f;p=sane-kds-s2000w-net.git fix memory leak config read --- 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;