utils: coverity resource leak warning
authorKevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Wed, 12 Jun 2019 15:38:39 +0000 (17:38 +0200)
committerKevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Wed, 12 Jun 2019 16:03:01 +0000 (18:03 +0200)
solve coverity reported resource leak (socket handle)

Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
utils.c

diff --git a/utils.c b/utils.c
index 7f0978724d5132d50d5af74d25291941cab9f237..fc6bbd7a3ec82d93f66aaf051bcfe556f1f98573 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -944,18 +944,24 @@ bool
 fw3_check_loopback_dev(const char *name)
 {
        struct ifreq ifr;
-       int s = socket(AF_LOCAL, SOCK_DGRAM, 0);
+       int s;
        bool rv = false;
 
+       s = socket(AF_LOCAL, SOCK_DGRAM, 0);
+
+       if (s < 0)
+               return false;
+
        memset(&ifr, 0, sizeof(ifr));
        strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name) - 1);
 
-       if (s < 0 || ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
-               goto out;
+       if (ioctl(s, SIOCGIFFLAGS, &ifr) >= 0) {
+               if (ifr.ifr_flags & IFF_LOOPBACK)
+                       rv = true;
+       }
+
+       close(s);
 
-       if (ifr.ifr_flags & IFF_LOOPBACK)
-               rv = true;
-out:
        return rv;
 }