From: Roy Marples Date: Thu, 21 Jul 2016 08:45:00 +0000 (+0000) Subject: Release option memory if there is a problem allocating a large X-Git-Tag: v6.11.2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4cba32ed596e5094e1efc78d4f05b72e2ef2f5b;p=thirdparty%2Fdhcpcd.git Release option memory if there is a problem allocating a large enough buffer to read the file. Thanks to Koichi Okamoto for the initial patch. --- diff --git a/if-options.c b/if-options.c index 3334d413..289b3bad 100644 --- a/if-options.c +++ b/if-options.c @@ -2340,19 +2340,25 @@ read_config(struct dhcpcd_ctx *ctx, buf = malloc(buflen); if (buf == NULL) { logger(ctx, LOG_ERR, "%s: %m", __func__); + free_options(ifo); return NULL; } ldop = edop = NULL; for (e = dhcpcd_embedded_conf; *e; e++) { ol = strlen(*e) + 1; if (ol > buflen) { + char *nbuf; + buflen = ol; - buf = realloc(buf, buflen); - if (buf == NULL) { - logger(ctx, LOG_ERR, "%s: %m", __func__); + nbuf = realloc(buf, buflen); + if (nbuf == NULL) { + logger(ctx, LOG_ERR, + "%s: %m", __func__); free(buf); + free_options(ifo); return NULL; } + buf = nbuf; } memcpy(buf, *e, ol); line = buf;