wifi_perc: Fix file descriptor leak
authorAaron Marcher <me@drkhsh.at>
Wed, 2 May 2018 17:41:53 +0000 (19:41 +0200)
committerAaron Marcher <me@drkhsh.at>
Wed, 2 May 2018 17:41:53 +0000 (19:41 +0200)
components/wifi.c

index 13b630aa122c538b4667cb5f1bbb2720f419841a..7cd2702ca1e9fc27666688167df1321fa5aa3725 100644 (file)
                                strerror(errno));
                        return NULL;
                }
-               if(!(p = fgets(status, 5, fp)) || strcmp(status, "up\n") != 0) {
+               p = fgets(status, 5, fp);
+               fclose(fp);
+               if(!p || strcmp(status, "up\n") != 0) {
                        return NULL;
                }
-               fclose(fp);
 
                if (!(fp = fopen("/proc/net/wireless", "r"))) {
                        fprintf(stderr, "fopen '/proc/net/wireless': %s\n",