Fix some clatd cloexec and file descriptor leaking via missing close()
Not terribly important since clatd doesn't exec anything,
but was muddying the waters while I was searching for other
fd-survives-across-exec leakage in netd. While at it also
fix another leaked fd which we forgot to close().
Test: builds and boots
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iceb7d4052dc9be29db5c7bb3fe2ee27da7864379
diff --git a/mtu.c b/mtu.c
index 567d177..472bd4e 100644
--- a/mtu.c
+++ b/mtu.c
@@ -22,6 +22,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <unistd.h>
#include "mtu.h"
@@ -33,14 +34,16 @@
int fd;
struct ifreq if_mtu;
- fd = socket(AF_INET, SOCK_STREAM, 0);
+ fd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd < 0) {
return -1;
}
strncpy(if_mtu.ifr_name, ifname, IFNAMSIZ);
if_mtu.ifr_name[IFNAMSIZ - 1] = '\0';
if (ioctl(fd, SIOCGIFMTU, &if_mtu) < 0) {
+ close(fd);
return -1;
}
+ close(fd);
return if_mtu.ifr_mtu;
}