From 53d4577a63fd1b9dc040c41522b25b08f6c43afc Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 3 Jul 2013 00:16:45 +0200 Subject: [PATCH] priv: avoid to leak generic socket Due to previous commit, a socket was requested for each operation needing it but it was not released. --- src/daemon/priv-linux.c | 4 +++- src/daemon/priv.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) 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)); } -- 2.47.2