Repository : ssh://git@open-mesh.org/alfred
On branch : master
commit e99382edc23ece11c0ad1fbd91aaefeb222c9cb4 Author: Matthias Schiffer mschiffer@universe-factory.net Date: Sun Jan 19 16:01:04 2014 +0100
batadv-vis: don't leak socket fd in get_if_mac()
Leaking an fd every time get_if_mac() is called causes a batadv-vis server process to hit the open file limit in a matter of hours when it is as low as 1024 (which it is on OpenWRT).
Reported-by: Jan-Philipp Litza janphilipp@litza.de Signed-off-by: Matthias Schiffer mschiffer@universe-factory.net Signed-off-by: Simon Wunderlich sw@simonwunderlich.de
e99382edc23ece11c0ad1fbd91aaefeb222c9cb4 vis/vis.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/vis/vis.c b/vis/vis.c index dcb4db4..7a8e780 100644 --- a/vis/vis.c +++ b/vis/vis.c @@ -96,7 +96,7 @@ static uint8_t *str_to_mac(char *str) static int get_if_mac(char *ifname, uint8_t *mac) { struct ifreq ifr; - int sock; + int sock, ret;
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
@@ -105,7 +105,11 @@ static int get_if_mac(char *ifname, uint8_t *mac) return -1; }
- if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { + ret = ioctl(sock, SIOCGIFHWADDR, &ifr); + + close(sock); + + if (ret == -1) { fprintf(stderr, "can't get MAC address: %s\n", strerror(errno)); return -1; }