public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] batadv-vis: don't leak socket fd in get_if_mac()
@ 2014-01-19 15:01 Matthias Schiffer
  2014-01-19 16:16 ` Antonio Quartulli
  2014-01-20 10:52 ` Simon Wunderlich
  0 siblings, 2 replies; 4+ messages in thread
From: Matthias Schiffer @ 2014-01-19 15:01 UTC (permalink / raw)
  To: b.a.t.m.a.n

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>
---
 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;
 	}
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-20 10:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-19 15:01 [B.A.T.M.A.N.] [PATCH] batadv-vis: don't leak socket fd in get_if_mac() Matthias Schiffer
2014-01-19 16:16 ` Antonio Quartulli
2014-01-19 16:43   ` Matthias Schiffer
2014-01-20 10:52 ` Simon Wunderlich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox