[PATCH v2] libiberty(argv.c): Fix memory leak in expandargv

libiberty:
	* argv.c (expandargv): free allocated buffer if read fails.
This commit is contained in:
Ayush Mittal 2021-02-18 21:59:03 -07:00 committed by Jeff Law
parent d909ead682
commit 0b2b7ef367
1 changed files with 4 additions and 1 deletions

View 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