Dynamic memory referenced by 'buffer' was allocated using xmalloc but fails to 
free it
when jump to 'error' label.

Issue as per static analysis tool.

Signed-off-by: Ayush Mittal <ayus...@samsung.com>
Signed-off-by: Maninder Singh <maninder...@samsung.com>
---
 libiberty/ChangeLog | 4 ++++
 libiberty/argv.c    | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index e472553..96cacba 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,7 @@
+2021-02-18  Ayush Mittal  <ayus...@samsung.com>
+
+       * argv.c (expandargv): Fix memory leak for buffer allocated to read 
file contents.
+
 2021-02-01  Martin Sebor  <mse...@redhat.com>
 
        * dyn-string.c (dyn_string_insert_cstr): Use memcpy instead of strncpy
diff --git a/libiberty/argv.c b/libiberty/argv.c
index cd97f90..7199c7d 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

Reply via email to