From 2e57ca9b3f534ab6c017579334f328ca96f03c2a Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Wed, 14 Feb 2024 16:06:14 +0100 Subject: [PATCH] close file and don't malloc for no reason --- modules/os.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/os.c b/modules/os.c index d32c610..2082759 100644 --- a/modules/os.c +++ b/modules/os.c @@ -44,7 +44,7 @@ const char *get(void) { ssize_t read; char *line = NULL; - char *name = malloc(1024 * sizeof(char)); + char *name = NULL; const char *name_label = "PRETTY_NAME="; const size_t name_label_len = strlen(name_label); @@ -61,6 +61,12 @@ const char *get(void) { break; } + fclose(os_release); + + if (name == NULL) { + name = "Unknown"; + } + if (asprintf(&ret, "OS: %s", name) < 0) { fprintf(stderr, "error: failed formatting string (this shouldn't happen)"); exit(EXIT_FAILURE);