]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix some more potential leaks and allow full build with dmalloc.
authorRoy Marples <roy@marples.name>
Wed, 14 Nov 2012 10:32:08 +0000 (10:32 +0000)
committerRoy Marples <roy@marples.name>
Wed, 14 Nov 2012 10:32:08 +0000 (10:32 +0000)
common.c
dhcpcd.c

index 05b547b7901a43d1a76059588c16ae8710fcda30..15fe3771fd627379b8d9a93c9b19b072407bd014 100644 (file)
--- a/common.c
+++ b/common.c
@@ -251,6 +251,7 @@ writepid(int fd, pid_t pid)
        return 0;
 }
 
+#ifndef xmalloc
 void *
 xmalloc(size_t s)
 {
@@ -262,16 +263,9 @@ xmalloc(size_t s)
        exit (EXIT_FAILURE);
        /* NOTREACHED */
 }
+#endif
 
-void *
-xzalloc(size_t s)
-{
-       void *value = xmalloc(s);
-
-       memset(value, 0, s);
-       return value;
-}
-
+#ifndef xrealloc
 void *
 xrealloc(void *ptr, size_t s)
 {
@@ -283,7 +277,9 @@ xrealloc(void *ptr, size_t s)
        exit(EXIT_FAILURE);
        /* NOTREACHED */
 }
+#endif
 
+#ifndef xstrdup
 char *
 xstrdup(const char *str)
 {
@@ -299,3 +295,13 @@ xstrdup(const char *str)
        exit(EXIT_FAILURE);
        /* NOTREACHED */
 }
+#endif
+
+void *
+xzalloc(size_t s)
+{
+       void *value = xmalloc(s);
+
+       memset(value, 0, s);
+       return value;
+}
index 33bb2c27a35e814fbec7b980fec296fb257bc885..f6b7e5ed5f475277e93907f818ad8056c3d7e167 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -97,6 +97,7 @@ static int ifc;
 static char *cffile;
 static char *pidfile;
 static int linkfd = -1, ipv6rsfd = -1, ipv6nsfd = -1;
+static uint8_t *packet;
 
 struct dhcp_op {
        uint8_t value;
@@ -188,6 +189,7 @@ cleanup(void)
        for (i = 0; i < ifdc; i++)
                free(ifdv[i]);
        free(ifdv);
+       free(packet);
 #endif
 
        if (linkfd != -1)
@@ -660,7 +662,6 @@ static void
 handle_dhcp_packet(void *arg)
 {
        struct interface *iface = arg;
-       uint8_t *packet;
        struct dhcp_message *dhcp = NULL;
        const uint8_t *pp;
        ssize_t bytes;
@@ -670,7 +671,8 @@ handle_dhcp_packet(void *arg)
        /* We loop through until our buffer is empty.
         * The benefit is that if we get >1 DHCP packet in our buffer and
         * the first one fails for any reason, we can use the next. */
-       packet = xmalloc(udp_dhcp_len);
+       if (packet == NULL)
+               packet = xmalloc(udp_dhcp_len);
        for(;;) {
                bytes = get_raw_packet(iface, ETHERTYPE_IP,
                    packet, udp_dhcp_len, &partialcsum);
@@ -739,6 +741,7 @@ handle_dhcp_packet(void *arg)
                        break;
        }
        free(packet);
+       packet = NULL;
        free(dhcp);
 }