On Thu, 18 Feb 2021 at 16:32, Ayush Mittal via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> 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.
AFAIK, the policy has changed to not include ChangeLog in patches anymore.
Instead the ChangeLog bits should be written in commit messages, and
the ChangeLog file
is updated automatically based on that.
> +
>  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;
> +       }
Sorry to nitpick for formatting issues - IIRC, the convention is to
use free (buffer) with space
between function name and "(". As a general note, please run patches
thru contrib/check_GNU_style.py.

The patch looks OK to me, but I can't approve.

Thanks,
Prathamesh
>        /* 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