From: Matthias Schiffer Date: Sat, 18 Jan 2014 21:15:16 +0100 Subject: alfred: fix socket fd leak diff --git a/alfred/patches/0002-batadv-vis-don-t-leak-socket-fd-in-get_if_mac.patch b/alfred/patches/0002-batadv-vis-don-t-leak-socket-fd-in-get_if_mac.patch new file mode 100644 index 0000000..2374e25 --- /dev/null +++ b/alfred/patches/0002-batadv-vis-don-t-leak-socket-fd-in-get_if_mac.patch @@ -0,0 +1,39 @@ +From 449b94ee85a42fbabec550d920002ad07738e733 Mon Sep 17 00:00:00 2001 +Message-Id: <449b94ee85a42fbabec550d920002ad07738e733.1390075976.git.mschiffer@universe-factory.net> +From: Matthias Schiffer +Date: Sat, 18 Jan 2014 21:04:05 +0100 +Subject: [PATCH] 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 there are many +active interfaces and the limit is as low as 1024 (which it is on OpenWRT). + +Reported-by: Jan-Philipp Litza +Signed-off-by: Matthias Schiffer +--- + vis/vis.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +--- a/vis/vis.c ++++ b/vis/vis.c +@@ -97,6 +97,7 @@ static int get_if_mac(char *ifname, uint + { + struct ifreq ifr; + int sock; ++ int ret; + + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + +@@ -105,7 +106,11 @@ static int get_if_mac(char *ifname, uint + 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; + }