diff options
| author | Roy Marples <roy@marples.name> | 2012-03-20 13:46:35 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2012-03-20 13:46:35 +0000 |
| commit | 02f1a2afaca4292813a83293aecc27ccd9bbe453 (patch) | |
| tree | 864d678b9c12541379d32cbf9498f50ac8e3a178 | |
| parent | 8cf1f9a8ca06c73a8192cadbe740ef7e26a9448e (diff) | |
| download | dhcpcd-02f1a2afaca4292813a83293aecc27ccd9bbe453.tar.xz | |
Use correct event loop timeout deletion to stop occasional segfaults.
Fix a memory leak and free our global buffers if debugging memory.
| -rw-r--r-- | ipv6rs.c | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -92,6 +92,16 @@ static unsigned char *rcvbuf; static unsigned char ansbuf[1500]; static char ntopbuf[INET6_ADDRSTRLEN]; +#if DEBUG_MEMORY +static void +ipv6rs_cleanup(void) +{ + + free(sndbuf); + free(rcvbuf); +} +#endif + int ipv6rs_open(void) { @@ -125,6 +135,10 @@ ipv6rs_open(void) &filt, sizeof(filt)) == -1) return -1; +#if DEBUG_MEMORY + atexit(ipv6rs_cleanup); +#endif + len = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int)); sndbuf = xzalloc(len); if (sndbuf == NULL) @@ -154,6 +168,7 @@ ipv6rs_makeprobe(struct interface *ifp) struct nd_router_solicit *rs; struct nd_opt_hdr *nd; + free(ifp->rs); ifp->rslen = sizeof(*rs) + ROUNDUP8(ifp->hwlen + 2); ifp->rs = xzalloc(ifp->rslen); if (ifp->rs == NULL) @@ -355,7 +370,6 @@ ipv6rs_handledata(_unused void *arg) syslog(LOG_INFO, "%s: Router Advertisement from %s", ifp->name, sfrom); } - delete_timeouts(ifp, NULL); if (rap == NULL) { rap = xmalloc(sizeof(*rap)); @@ -542,7 +556,7 @@ ipv6rs_handledata(_unused void *arg) if (has_dns) delete_q_timeout(0, handle_exit_timeout, NULL); - delete_timeouts(ifp, NULL); + delete_timeout(NULL, ifp); ipv6rs_expire(ifp); if (has_dns) daemonise(); @@ -653,11 +667,14 @@ ipv6rs_free(struct interface *ifp) { struct ra *rap, *ran; + free(ifp->rs); + ifp->rs = NULL; for (rap = ifp->ras; rap && (ran = rap->next, 1); rap = ran) { ipv6rs_free_opts(rap); free(rap->data); free(rap); } + ifp->ras = NULL; } void @@ -732,7 +749,7 @@ int ipv6rs_start(struct interface *ifp) { - delete_timeouts(ifp, NULL); + delete_timeout(NULL, ifp); /* Always make a new probe as the underlying hardware * address could have changed. */ |
