[PATCH] string: Fix memory leak in argz-addsep.c

SAMKO samko.balazi@gmail.com
Fri Jun 26 07:48:51 GMT 2026


Yes, please. Since I do not have commit access, I would greatly appreciate
it if you could push this for me.
Thank you both for your time and the review.

On Fri, Jun 26, 2026 at 3:58 AM Andreas K. Huettel <dilfridge@gentoo.org>
wrote:

> Am Dienstag, 23. Juni 2026, 01:16:17 Japanische Normalzeit schrieb
> Adhemerval Zanella Netto:
> >
> > On 19/06/26 10:11, Samuel Balazi wrote:
> > > Assign the realloc result to a temporary variable, so the original
> > > memory block is not lost if the allocation fails.
> >
> > LGTM, thanks.
> >
> > Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
>
> OK (do you need help pushing it?)
>
> >
> > > ---
> > >  string/argz-addsep.c | 6 ++++--
> > >  1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/string/argz-addsep.c b/string/argz-addsep.c
> > > index 509559dee4..a077d9c7c0 100644
> > > --- a/string/argz-addsep.c
> > > +++ b/string/argz-addsep.c
> > > @@ -30,10 +30,12 @@ __argz_add_sep (char **argz, size_t *argz_len,
> const char *string, int delim)
> > >      {
> > >        const char *rp;
> > >        char *wp;
> > > +      char *tmp_argz;
> > >
> > > -      *argz = (char *) realloc (*argz, *argz_len + nlen);
> > > -      if (*argz == NULL)
> > > +      tmp_argz = (char *) realloc (*argz, *argz_len + nlen);
> > > +      if (tmp_argz == NULL)
> > >     return ENOMEM;
> > > +      *argz = tmp_argz;
> > >
> > >        wp = *argz + *argz_len;
> > >        rp = string;
> >
> >
>
>
> --
> PD Dr. Andreas K. Hüttel
> dilfridge@gentoo.org
> Gentoo Linux developer
> (council, comrel, toolchain, base-system, perl, libreoffice)
> https://wiki.gentoo.org/wiki/User:Dilfridge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20260626/ae468ad1/attachment.htm>


More information about the Libc-alpha mailing list