From: Roy Marples Date: Fri, 6 May 2016 16:23:26 +0000 (+0000) Subject: Free the getline buffer if needed. X-Git-Tag: v6.11.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=176b729cb184bb032a5ac727c6848c41b2143769;p=thirdparty%2Fdhcpcd.git Free the getline buffer if needed. --- diff --git a/common.c b/common.c index fae6adcb..abd15f88 100644 --- a/common.c +++ b/common.c @@ -358,10 +358,15 @@ read_hwaddr_aton(uint8_t **data, const char *path) *data = NULL; while ((llen = getline(&buf, &buf_len, fp)) != -1) { if ((len = hwaddr_aton(NULL, buf)) != 0) { - if ((*data = malloc(len)) != NULL) + 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); - else - len = 0; break; } }