[PATCH] string: Fix memory leak in argz-addsep.c
Andreas K. Huettel
dilfridge@gentoo.org
Fri Jun 26 01:58:10 GMT 2026
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 --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 870 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20260626/9fc1816c/attachment.sig>
More information about the Libc-alpha
mailing list