close file and don't malloc for no reason

This commit is contained in:
jacekpoz 2024-02-14 16:06:14 +01:00
parent e405ccdf2a
commit 2e57ca9b3f
No known key found for this signature in database
GPG key ID: 94E812A8B12AAE3C

View file

@ -44,7 +44,7 @@ const char *get(void) {
ssize_t read; ssize_t read;
char *line = NULL; char *line = NULL;
char *name = malloc(1024 * sizeof(char)); char *name = NULL;
const char *name_label = "PRETTY_NAME="; const char *name_label = "PRETTY_NAME=";
const size_t name_label_len = strlen(name_label); const size_t name_label_len = strlen(name_label);
@ -61,6 +61,12 @@ const char *get(void) {
break; break;
} }
fclose(os_release);
if (name == NULL) {
name = "Unknown";
}
if (asprintf(&ret, "OS: %s", name) < 0) { if (asprintf(&ret, "OS: %s", name) < 0) {
fprintf(stderr, "error: failed formatting string (this shouldn't happen)"); fprintf(stderr, "error: failed formatting string (this shouldn't happen)");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);