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

Ayush Mittal ayush.m@samsung.com
Thu Feb 18 12:08:45 GMT 2021


libiberty/ChangeLog:

	* argv.c (expandargv): free allocated buffer if read fails.

Signed-off-by: Ayush Mittal <ayush.m@samsung.com>
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
---
v1 -> v2: corrected formatting and changelog commit

 libiberty/argv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libiberty/argv.c b/libiberty/argv.c
index cd97f90..48dcd10 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
-- 
1.9.1



More information about the Gcc-patches mailing list