]> git.sur5r.net Git - i3/i3status/commitdiff
Plug an fd leak in the OpenBSD-specific code for _first_ 202/head
authorJasper Lievisse Adriaanse <jasper@humppa.nl>
Tue, 7 Feb 2017 18:23:53 +0000 (19:23 +0100)
committerJasper Lievisse Adriaanse <jasper@humppa.nl>
Tue, 7 Feb 2017 18:29:01 +0000 (19:29 +0100)
src/first_network_device.c

index 4e680069290b9120f6d493baf78c4d62851a6cef..593238531223bd401696d94d9cc3e389db05a7d2 100644 (file)
@@ -94,18 +94,21 @@ static net_type_t iface_type(const char *ifname) {
     strlcpy(bssid.i_name, ifname, sizeof(bssid.i_name));
     ibssid = ioctl(s, SIOCG80211BSSID, &bssid);
 
-    if (ibssid == 0 || inwid == 0)
+    if (ibssid == 0 || inwid == 0) {
+        close(s);
         return NET_TYPE_WIRELESS;
+    }
 
     (void)memset(&ifmr, 0, sizeof(ifmr));
     (void)strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
 
-    if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
+    if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
+        close(s);
         return NET_TYPE_OTHER;
-    else
+    } else {
+        close(s);
         return NET_TYPE_ETHERNET;
-
-    close(s);
+    }
 #else
 #error Missing implementation to determine interface type.
 #endif