]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
priv: avoid to leak generic socket
authorVincent Bernat <bernat@luffy.cx>
Tue, 2 Jul 2013 22:16:45 +0000 (00:16 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 2 Jul 2013 22:16:45 +0000 (00:16 +0200)
Due to previous commit, a socket was requested for each operation
needing it but it was not released.

src/daemon/priv-linux.c
src/daemon/priv.c

index 553a85316a862e16c1d6f3187790fd6e89bbc8f6..32efc192fd765bbeaff319f81076fbd514b43273 100644 (file)
@@ -124,7 +124,7 @@ asroot_ethtool()
 {
        struct ifreq ifr = {};
        struct ethtool_cmd ethc = {};
-       int len, rc, sock;
+       int len, rc, sock = -1;
        char *ifname;
 
        must_read(&len, sizeof(int));
@@ -138,9 +138,11 @@ asroot_ethtool()
        ethc.cmd = ETHTOOL_GSET;
        if (((rc = sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) ||
            (rc = ioctl(sock, SIOCETHTOOL, &ifr)) != 0) {
+               if (sock != -1) close(sock);
                must_write(&rc, sizeof(int));
                return;
        }
+       close(sock);
        must_write(&rc, sizeof(int));
        must_write(&ethc, sizeof(struct ethtool_cmd));
 }
index 8cc61001c69c75b337caeba33e72f946086be0c7..7c95c5a9a33c85c1a7b37d71d474cd4b0cdb9c1a 100644 (file)
@@ -212,7 +212,7 @@ asroot_iface_init()
 static void
 asroot_iface_multicast()
 {
-       int sock, add, rc = 0;
+       int sock = -1, add, rc = 0;
        struct ifreq ifr = { .ifr_name = {} };
        must_read(ifr.ifr_name, IFNAMSIZ);
 #if defined HOST_OS_LINUX
@@ -244,6 +244,7 @@ asroot_iface_multicast()
                    &ifr) < 0) && (errno != EADDRINUSE)))
                rc = errno;
 
+       if (sock != -1) close(sock);
        must_write(&rc, sizeof(rc));
 }