From: Vincent Bernat Date: Tue, 2 Jul 2013 22:16:45 +0000 (+0200) Subject: priv: avoid to leak generic socket X-Git-Tag: 0.7.6~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=53d4577a63fd1b9dc040c41522b25b08f6c43afc;p=thirdparty%2Flldpd.git priv: avoid to leak generic socket Due to previous commit, a socket was requested for each operation needing it but it was not released. --- diff --git a/src/daemon/priv-linux.c b/src/daemon/priv-linux.c index 553a8531..32efc192 100644 --- a/src/daemon/priv-linux.c +++ b/src/daemon/priv-linux.c @@ -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(ðc, sizeof(struct ethtool_cmd)); } diff --git a/src/daemon/priv.c b/src/daemon/priv.c index 8cc61001..7c95c5a9 100644 --- a/src/daemon/priv.c +++ b/src/daemon/priv.c @@ -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)); }