From: Ayush Mittal Date: Fri, 19 Feb 2021 04:59:03 +0000 (-0700) Subject: [PATCH v2] libiberty(argv.c): Fix memory leak in expandargv X-Git-Tag: basepoints/gcc-12~967 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b2b7ef3676920c120d9b329e5b65924650ab44c;p=thirdparty%2Fgcc.git [PATCH v2] libiberty(argv.c): Fix memory leak in expandargv libiberty: * argv.c (expandargv): free allocated buffer if read fails. --- diff --git a/libiberty/argv.c b/libiberty/argv.c index cd97f9071c2f..48dcd102461f 100644 --- a/libiberty/argv.c +++ b/libiberty/argv.c @@ -442,7 +442,10 @@ expandargv (int *argcp, char ***argvp) due to CR/LF->CR translation when reading text files. That does not in-and-of itself indicate failure. */ && ferror (f)) - goto error; + { + free (buffer); + goto error; + } /* Add a NUL terminator. */ buffer[len] = '\0'; /* If the file is empty or contains only whitespace, buildargv would