[PATCH v2] libiberty(argv.c): Fix memory leak in expandargv
authorAyush Mittal <ayush.m@samsung.com>
Fri, 19 Feb 2021 04:59:03 +0000 (21:59 -0700)
committerJeff Law <law@redhat.com>
Fri, 19 Feb 2021 05:00:06 +0000 (22:00 -0700)
libiberty:
* argv.c (expandargv): free allocated buffer if read fails.

libiberty/argv.c

index cd97f9071c2f2508a63c2e40bd95985330464952..48dcd102461f69d70331a73975109ddbc5766e66 100644 (file)
@@ -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