|
|
Message-ID: <20260805115141.GM3520958@port70.net>
Date: Wed, 5 Aug 2026 13:51:41 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: Matthias Goergens <matthias.goergens@...il.com>
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH] wordexp: free word on vector allocation failure
* Matthias Goergens <matthias.goergens@...il.com> [2026-08-05 15:57:59 +0800]:
> getword allocates the next expanded word before the result vector is
> grown. If realloc fails, that word has not been stored in the vector and
> cannot be reached by wordfree, so returning WRDE_NOSPACE leaks it.
>
> Free the exclusively owned word before leaving the loop. Existing
> partial results and the returned error are unchanged.
looks ok.
fixes a memory leak.
> ---
> src/misc/wordexp.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/misc/wordexp.c b/src/misc/wordexp.c
> index db83a69f..db3e0067 100644
> --- a/src/misc/wordexp.c
> +++ b/src/misc/wordexp.c
> @@ -136,7 +136,10 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags)
> if (i+1 >= l) {
> l += l/2+10;
> tmp = realloc(wv, l*sizeof(char *));
> - if (!tmp) break;
> + if (!tmp) {
> + free(w);
> + break;
> + }
> wv = tmp;
> }
> wv[i++] = w;
> --
> 2.55.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.