summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroy@uberlaptop.marples.name <roy@uberlaptop.marples.name>2012-03-27 16:30:33 +0000
committerroy@uberlaptop.marples.name <roy@uberlaptop.marples.name>2012-03-27 16:30:33 +0000
commitdcc1e564e7930b2425958560e108bca55a639b35 (patch)
tree6f0db46a9456927bcb5e201f84dd9bb1f14fc468
parent9cf974fea3154a9b3fd90e77970f6d86f2669e51 (diff)
downloaddhcpcd-dcc1e564e7930b2425958560e108bca55a639b35.tar.xz
Fix some valgrind errors on FreeBSD
-rw-r--r--compat/closefrom.c5
-rw-r--r--if-bsd.c15
-rw-r--r--net.c16
3 files changed, 36 insertions, 0 deletions
diff --git a/compat/closefrom.c b/compat/closefrom.c
index 664c4bc3..570637d2 100644
--- a/compat/closefrom.c
+++ b/compat/closefrom.c
@@ -36,6 +36,11 @@ closefrom(int fd)
int i;
int r = 0;
+#ifdef _SC_OPEN_MAX
+ max = sysconf(_SC_OPEN_MAX);
+#else
+ max = getdtablesize();
+#endif
for (i = fd; i < max; i++)
r += close(i);
return r;
diff --git a/if-bsd.c b/if-bsd.c
index c959b5e4..af98863c 100644
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -90,6 +90,15 @@ if_conf(_unused struct interface *iface)
return 0;
}
+#ifdef DEBUG_MEMORY
+static void
+cleanup(void)
+{
+
+ free(link_buf);
+}
+#endif
+
int
init_sockets(void)
{
@@ -129,6 +138,7 @@ getifssid(const char *ifname, char *ssid)
strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name));
ireq.i_type = IEEE80211_IOC_SSID;
ireq.i_val = -1;
+ memset(nwid, 0, sizeof(nwid));
ireq.i_data = &nwid;
if (ioctl(socket_afnet, SIOCG80211, &ireq) == 0) {
retval = ireq.i_len;
@@ -267,6 +277,11 @@ open_link_socket(void)
{
int fd;
+#ifdef DEBUG_MEMORY
+ if (link_buf == NULL)
+ atexit(cleanup);
+#endif
+
fd = socket(PF_ROUTE, SOCK_RAW, 0);
if (fd != -1) {
set_cloexec(fd);
diff --git a/net.c b/net.c
index 14322b19..d8c972ce 100644
--- a/net.c
+++ b/net.c
@@ -74,6 +74,21 @@ static char hwaddr_buffer[(HWADDR_LEN * 3) + 1];
int socket_afnet = -1;
+#if defined(__FreeBSD__) && defined(DEBUG_MEMORY)
+/* FreeBSD does not zero the struct, causing valgrind errors */
+unsigned int
+if_nametoindex(const char *ifname)
+{
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ if (ioctl(socket_afnet, SIOCGIFINDEX, &ifr) != -1)
+ return ifr.ifr_index;
+ return 0;
+}
+#endif
+
int
inet_ntocidr(struct in_addr address)
{
@@ -242,6 +257,7 @@ free_interface(struct interface *iface)
free(iface->state->offer);
free(iface->state);
}
+ free(iface->buffer);
free(iface->clientid);
free(iface);
}