Close fd if there was an empty return.

* Not closing will use up all file descriptors over time.
This commit is contained in:
Christoph Lohmann 2023-01-29 12:15:22 +01:00
parent a30f9f5bd1
commit 81cdc8f4a2
1 changed files with 3 additions and 1 deletions

View File

@ -106,8 +106,10 @@ readfile(char *base, char *file)
if (fd == NULL) if (fd == NULL)
return NULL; return NULL;
if (fgets(line, sizeof(line)-1, fd) == NULL) if (fgets(line, sizeof(line)-1, fd) == NULL) {
fclose(fd);
return NULL; return NULL;
}
fclose(fd); fclose(fd);
return smprintf("%s", line); return smprintf("%s", line);