]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix some valgrind errors on FreeBSD
authorroy@uberlaptop.marples.name <roy@uberlaptop.marples.name>
Tue, 27 Mar 2012 16:30:33 +0000 (16:30 +0000)
committerroy@uberlaptop.marples.name <roy@uberlaptop.marples.name>
Tue, 27 Mar 2012 16:30:33 +0000 (16:30 +0000)
compat/closefrom.c
if-bsd.c
net.c

index 664c4bc3e38d8e98c0fc182b39d38ac28408db4d..570637d29617479f889756dc2981a8b174a2ebed 100644 (file)
@@ -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;
index c959b5e41bad31fb725e1b1fd5929b40e2dc73f7..af98863c6d0d9024dbf9f30515c21285bff0f8f7 100644 (file)
--- 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 14322b190a6ff99626c8fc0e2307bf06f91d12cf..d8c972ce98ae553106d5ca90224ef5fc3d238042 100644 (file)
--- 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);
 }