[hackers] [dwmstatus] Close fd if there was an empty return. || Christoph Lohmann

From: <git_AT_suckless.org>
Date: Sun, 29 Jan 2023 12:15:54 +0100 (CET)

commit 81cdc8f4a2528374842049c214937349b30fbebc
Author: Christoph Lohmann <20h_AT_r-36.net>
AuthorDate: Sun Jan 29 12:15:22 2023 +0100
Commit: Christoph Lohmann <20h_AT_r-36.net>
CommitDate: Sun Jan 29 12:15:22 2023 +0100

    Close fd if there was an empty return.
    
    * Not closing will use up all file descriptors over time.

diff --git a/dwmstatus.c b/dwmstatus.c
index a8cd4ac..1b53292 100644
--- a/dwmstatus.c
+++ b/dwmstatus.c
_AT_@ -106,8 +106,10 @@ readfile(char *base, char *file)
         if (fd == NULL)
                 return NULL;
 
- if (fgets(line, sizeof(line)-1, fd) == NULL)
+ if (fgets(line, sizeof(line)-1, fd) == NULL) {
+ fclose(fd);
                 return NULL;
+ }
         fclose(fd);
 
         return smprintf("%s", line);
Received on Sun Jan 29 2023 - 12:15:54 CET

This archive was generated by hypermail 2.3.0 : Sun Jan 29 2023 - 12:24:32 CET