summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2012-11-14 10:31:49 +0000
committerRoy Marples <roy@marples.name>2012-11-14 10:31:49 +0000
commit2534ef40f282896d5803d38b8f4e561ce6e731e8 (patch)
treec3b0d2a74c8331ef96e01d0129886ce9312c4821
parenta8d26e9d7b4019a73aa28acc94a8f03e4c0c3781 (diff)
downloaddhcpcd-2534ef40f282896d5803d38b8f4e561ce6e731e8.tar.xz
Plug some memory leaks.
-rw-r--r--dhcpcd.c8
-rw-r--r--eloop.c11
-rw-r--r--eloop.h1
3 files changed, 15 insertions, 5 deletions
diff --git a/dhcpcd.c b/dhcpcd.c
index bad48843..33bb2c27 100644
--- 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 1115d899..51fe0ac4 100644
--- 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 ece43c13..23c3626c 100644
--- 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