From: Roy Marples Date: Fri, 6 May 2016 16:28:54 +0000 (+0000) Subject: Fix some memory issues. X-Git-Tag: v6.11.0~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=253643935822b1c29c222ba3a68222b1733e2327;p=thirdparty%2Fdhcpcd.git Fix some memory issues. --- diff --git a/common.c b/common.c index abd15f88..8c6060c6 100644 --- a/common.c +++ b/common.c @@ -361,12 +361,13 @@ read_hwaddr_aton(uint8_t **data, const char *path) if (buf_len >= len) *data = (uint8_t *)buf; else { - free(buf); if ((*data = malloc(len)) == NULL) len = 0; } if (len != 0) - len = hwaddr_aton(*data, buf); + (void)hwaddr_aton(*data, buf); + if (buf_len < len) + free(buf); break; } } diff --git a/duid.c b/duid.c index 156742ad..9105fb01 100644 --- a/duid.c +++ b/duid.c @@ -113,6 +113,9 @@ duid_get(uint8_t **d, const struct interface *ifp) } } + /* Regardless of what happens we will create a DUID to use. */ + *d = data; + /* No file? OK, lets make one based on our interface */ if (ifp->family == ARPHRD_NETROM) { logger(ifp->ctx, LOG_WARNING, @@ -133,7 +136,6 @@ duid_get(uint8_t **d, const struct interface *ifp) } } - *d = data; if (!(fp = fopen(DUID, "w"))) { logger(ifp->ctx, LOG_ERR, "error writing DUID: %s: %m", DUID); return duid_make(data, ifp, DUID_LL);