0002-alfred-fix-socket-fd-leak.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sat, 18 Jan 2014 21:15:16 +0100
  3. Subject: alfred: fix socket fd leak
  4. 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
  5. new file mode 100644
  6. index 0000000..2374e25
  7. --- /dev/null
  8. +++ b/alfred/patches/0002-batadv-vis-don-t-leak-socket-fd-in-get_if_mac.patch
  9. @@ -0,0 +1,39 @@
  10. +From 449b94ee85a42fbabec550d920002ad07738e733 Mon Sep 17 00:00:00 2001
  11. +Message-Id: <449b94ee85a42fbabec550d920002ad07738e733.1390075976.git.mschiffer@universe-factory.net>
  12. +From: Matthias Schiffer <mschiffer@universe-factory.net>
  13. +Date: Sat, 18 Jan 2014 21:04:05 +0100
  14. +Subject: [PATCH] batadv-vis: don't leak socket fd in get_if_mac()
  15. +
  16. +Leaking an fd every time get_if_mac() is called causes a batadv-vis server
  17. +process to hit the open file limit in a matter of hours when there are many
  18. +active interfaces and the limit is as low as 1024 (which it is on OpenWRT).
  19. +
  20. +Reported-by: Jan-Philipp Litza <janphilipp@litza.de>
  21. +Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  22. +---
  23. + vis/vis.c | 7 ++++++-
  24. + 1 file changed, 6 insertions(+), 1 deletion(-)
  25. +
  26. +--- a/vis/vis.c
  27. ++++ b/vis/vis.c
  28. +@@ -97,6 +97,7 @@ static int get_if_mac(char *ifname, uint
  29. + {
  30. + struct ifreq ifr;
  31. + int sock;
  32. ++ int ret;
  33. +
  34. + strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
  35. +
  36. +@@ -105,7 +106,11 @@ static int get_if_mac(char *ifname, uint
  37. + return -1;
  38. + }
  39. +
  40. +- if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) {
  41. ++ ret = ioctl(sock, SIOCGIFHWADDR, &ifr);
  42. ++
  43. ++ close(sock);
  44. ++
  45. ++ if (ret == -1) {
  46. + fprintf(stderr, "can't get MAC address: %s\n", strerror(errno));
  47. + return -1;
  48. + }