]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Plug some memory leaks.
authorRoy Marples <roy@marples.name>
Wed, 14 Nov 2012 10:31:49 +0000 (10:31 +0000)
committerRoy Marples <roy@marples.name>
Wed, 14 Nov 2012 10:31:49 +0000 (10:31 +0000)
dhcpcd.c
eloop.c
eloop.h

index bad488437388747b9480fad6efb2155ffce04273..33bb2c27a35e814fbec7b980fec296fb257bc885 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -825,7 +825,8 @@ configure_interface1(struct interface *iface)
                        duid = xmalloc(DUID_LEN);
                        if ((len = get_duid(duid, iface)) == 0)
                                syslog(LOG_ERR, "get_duid: %m");
-               }
+               } else
+                       duid = NULL;
                if (len > 0) {
                        iface->clientid = xmalloc(len + 6);
                        iface->clientid[0] = len + 5;
@@ -849,6 +850,7 @@ configure_interface1(struct interface *iface)
                        memcpy(iface->clientid + 2, iface->hwaddr,
                            iface->hwlen);
                }
+               free(duid);
        }
        if (ifo->options & DHCPCD_CLIENTID)
                syslog(LOG_DEBUG, "%s: using ClientID %s", iface->name,
@@ -1994,6 +1996,10 @@ main(int argc, char **argv)
 
        syslog(LOG_INFO, "version " VERSION " starting");
 
+#ifdef DEBUG_MEMORY
+       eloop_init();
+#endif
+
        if ((signal_fd = signal_init()) == -1)
                exit(EXIT_FAILURE);
        if (signal_setup() == -1)
diff --git a/eloop.c b/eloop.c
index 1115d89917664f6064a722e0ba0acd5a19dfe54e..51fe0ac4e5a1a4d6c53fb8fb35be6394bb44b8f3 100644 (file)
--- a/eloop.c
+++ b/eloop.c
@@ -276,6 +276,13 @@ cleanup(void)
        }
        free(fds);
 }
+
+void
+eloop_init(void)
+{
+
+       atexit(cleanup);
+}
 #endif
 
 _noreturn void
@@ -287,10 +294,6 @@ start_eloop(void)
        struct timeout *t;
        struct timeval tv;
 
-#ifdef DEBUG_MEMORY
-       atexit(cleanup);
-#endif
-
        for (;;) {
                /* Run all timeouts first.
                 * When we have one that has not yet occured,
diff --git a/eloop.h b/eloop.h
index ece43c1322e6b99a3743e04394d981a842f19995..23c3626c0fd9b9b5796009862eff15a196743733 100644 (file)
--- a/eloop.h
+++ b/eloop.h
@@ -46,6 +46,7 @@ void add_q_timeout_tv(int queue, const struct timeval *, void (*)(void *),
     void *);
 void delete_q_timeout(int, void (*)(void *), void *);
 void delete_q_timeouts(int, void *, void (*)(void *), ...);
+void eloop_init(void);
 void start_eloop(void);
 
 #endif