From: Patrick Steinhardt <ps@pks.im>
To: Mike Hommey <mh@glandium.org>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH 2/4] Fix use-after-free warning with GCC at -O3
Date: Wed, 4 Jun 2025 09:36:07 +0200 [thread overview]
Message-ID: <aD_3ZzWSbyXIk81_@pks.im> (raw)
In-Reply-To: <20250603230646.2322671-2-mh@glandium.org>
On Wed, Jun 04, 2025 at 08:06:44AM +0900, Mike Hommey wrote:
> ```
> reftable/basics.c: In function ‘parse_names’:
> reftable/basics.c:233:17: error: pointer ‘names’ may be used after ‘free’ [-Werror=use-after-free]
> 233 | reftable_free(names[i]);
> | ^~~~~~~~~~~~~~~~~~~~~~~
> In function ‘reftable_free’,
> inlined from ‘reftable_realloc’ at reftable/basics.c:30:3,
> inlined from ‘reftable_realloc’ at reftable/basics.c:27:7,
> inlined from ‘reftable_alloc_grow’ at reftable/basics.h:228:10,
> inlined from ‘parse_names’ at reftable/basics.c:214:8:
> reftable/basics.c:44:17: note: call to ‘free’ here
> 44 | free(p);
> | ^~~~~~~
> ```
Same here, only posting the warning isn't sufficient to explain what's
going on.
> diff --git a/reftable/basics.c b/reftable/basics.c
> index 9988ebd635..de21fe6ef7 100644
> --- a/reftable/basics.c
> +++ b/reftable/basics.c
> @@ -229,9 +229,11 @@ char **parse_names(char *buf, int size)
> return names;
>
> err:
> - for (size_t i = 0; i < names_len; i++)
> - reftable_free(names[i]);
> - reftable_free(names);
> + if (names) {
> + for (size_t i = 0; i < names_len; i++)
> + reftable_free(names[i]);
> + reftable_free(names);
> + }
> return NULL;
> }
This change shouldn't be needed in theory: `names_len` has a positive
value if and only if `names` is non-NULL. So the warning is a false
positive.
That being said I'm not opposed to squelching this warning. But details
like this should be explained in the commit message.
Patrick
next prev parent reply other threads:[~2025-06-04 7:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-03 23:06 [PATCH 1/4] Fix maybe-uninitialized warning with GCC at -O3 Mike Hommey
2025-06-03 23:06 ` [PATCH 2/4] Fix use-after-free " Mike Hommey
2025-06-03 23:47 ` Junio C Hamano
2025-06-04 7:36 ` Patrick Steinhardt [this message]
2025-06-03 23:06 ` [PATCH 3/4] Fix comma warnings with clang on Windows Mike Hommey
2025-06-03 23:51 ` Junio C Hamano
2025-06-03 23:06 ` [PATCH 4/4] Fix unreachable-code warning " Mike Hommey
2025-06-04 7:36 ` Patrick Steinhardt
2025-06-04 15:50 ` Junio C Hamano
2025-06-04 7:36 ` [PATCH 1/4] Fix maybe-uninitialized warning with GCC at -O3 Patrick Steinhardt
2025-06-06 0:23 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aD_3ZzWSbyXIk81_@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mh@glandium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.