From: Roy Marples Date: Wed, 14 Nov 2012 10:31:49 +0000 (+0000) Subject: Plug some memory leaks. X-Git-Tag: v5.6.3~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2534ef40f282896d5803d38b8f4e561ce6e731e8;p=thirdparty%2Fdhcpcd.git Plug some memory leaks. --- 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