[hackers] [slstatus] close file descriptors and fix return values || Michael Buch

From: <git_AT_suckless.org>
Date: Wed, 13 Feb 2019 15:23:16 +0100 (CET)

commit a9193a757a510e07e69b18ca64d2e50d467f01c1
Author: Michael Buch <michaelbuch12_AT_gmail.com>
AuthorDate: Wed Feb 13 14:16:17 2019 +0000
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Wed Feb 13 15:23:04 2019 +0100

    close file descriptors and fix return values

diff --git a/components/wifi.c b/components/wifi.c
index d99c46c..92c252e 100644
--- a/components/wifi.c
+++ b/components/wifi.c
_AT_@ -211,14 +211,16 @@
                 int rssi_dbm;
                 int sockfd;
                 size_t len;
+ const char *fmt;
 
                 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                         warn("socket 'AF_INET':");
- return 0;
+ return NULL;
                 }
 
                 /* Retreive MAC address of interface */
                 len = IEEE80211_ADDR_LEN;
+ fmt = NULL;
                 if (load_ieee80211req(sockfd, interface, &bssid, IEEE80211_IOC_BSSID, &len))
                 {
                         /* Retrieve info on station with above BSSID */
_AT_@ -229,12 +231,13 @@
                         if (load_ieee80211req(sockfd, interface, &info, IEEE80211_IOC_STA_INFO, &len)) {
                                 rssi_dbm = info.sta.info[0].isi_noise +
                                                   info.sta.info[0].isi_rssi / 2;
- return bprintf("%d", RSSI_TO_PERC(rssi_dbm));
+
+ fmt = bprintf("%d", RSSI_TO_PERC(rssi_dbm));
                         }
                 }
 
                 close(sockfd);
- return NULL;
+ return fmt;
         }
 
         const char *
_AT_@ -243,12 +246,14 @@
                 char ssid[IEEE80211_NWID_LEN + 1];
                 size_t len;
                 int sockfd;
+ const char *fmt;
 
                 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                         warn("socket 'AF_INET':");
- return 0;
+ return NULL;
                 }
 
+ fmt = NULL;
                 len = sizeof(ssid);
                 memset(&ssid, 0, len);
                 if (load_ieee80211req(sockfd, interface, &ssid, IEEE80211_IOC_SSID, &len )) {
_AT_@ -258,9 +263,10 @@
                                 len = sizeof(ssid);
 
                         ssid[len - 1] = '\0';
- return bprintf("%s", ssid);
+ fmt = bprintf("%s", ssid);
                 }
 
- return NULL;
+ close(sockfd);
+ return fmt;
         }
 #endif
Received on Wed Feb 13 2019 - 15:23:16 CET

This archive was generated by hypermail 2.3.0 : Wed Feb 13 2019 - 15:24:21 CET