]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Free the getline buffer if needed.
authorRoy Marples <roy@marples.name>
Fri, 6 May 2016 16:23:26 +0000 (16:23 +0000)
committerRoy Marples <roy@marples.name>
Fri, 6 May 2016 16:23:26 +0000 (16:23 +0000)
common.c

index fae6adcb6e3959ceab1aea0581181f53af24b521..abd15f880df29a8c9a16b48ee257d32bb6585e16 100644 (file)
--- 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;
                }
        }