From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: Nicolas Le Cam <niko.lecam@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] revision: hang on to "freed" argv elements
Date: Tue, 1 Sep 2026 13:08:18 +0200 [thread overview]
Message-ID: <apayIuf9kXQcQPvS@pks.im> (raw)
In-Reply-To: <20260901092120.GA2979683@coredump.intra.peff.net>
On Tue, Sep 01, 2026 at 05:21:20AM -0400, Jeff King wrote:
> On Tue, Sep 01, 2026 at 10:51:26AM +0200, Patrick Steinhardt wrote:
[snip]
> > > +static void mark_argv_for_free(struct rev_info *revs, const char *str)
> > > +{
> > > + if (!str)
> > > + return;
> > > + strvec_push_nodup(&revs->argv_to_free, (char *)str);
> > > +}
> >
> > Hm. Doesn't this mean that we take ownership of the string and then
> > eventually try to release it when releasing the vector? I wonder whether
> > this could introduce subtle lifetime issues where the caller passes a
> > non-heap-allocated string.
>
> Yes, that's exactly the point. We are replacing a call to free() with
> one that passes ownership to a strvec which later frees it. If somebody
> is passing a non-heap string along with free_removed_argv_elements, then
> everything was already broken.
Fair.
> > I don't think it's that bad when seeing where we use these. But I feel
> > like hiding this fact by marking the parameter as `const` is a bit of a
> > weird design choice. I'd much rather prefer we force this onto the
> > callers so that they are aware of this, but I haven't seen the end
> > result of that. So maybe it's just too ugly.
>
> You can see the effect already in the diff. In the preimage all of the
> callers had to cast away const-ness in order to pass the string to
> free(). We could keep doing that here, but since this function has
> exactly one purpose (to free the string we pass it) it seems like a nice
> syntactic convenience to push the cast in here.
Okay, fair enough.
> Though you may want to look at the "2/1" I sent, which pushes the check
> for free_removed_argv_elements into this function. And then the cast and
> that check are side-by-side.
Makes sense, thanks!
Patrick
prev parent reply other threads:[~2026-09-01 11:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 21:55 [BUG] git stash show --src-prefix prints freed memory since 2.52.0 Nicolas Le Cam
2026-09-01 6:28 ` [PATCH] revision: hang on to "freed" argv elements Jeff King
2026-09-01 6:36 ` [PATCH 2/1] revision: simplify mark_argv_for_free() callers Jeff King
2026-09-01 18:02 ` Junio C Hamano
2026-09-01 8:51 ` [PATCH] revision: hang on to "freed" argv elements Patrick Steinhardt
2026-09-01 9:21 ` Jeff King
2026-09-01 11:08 ` Patrick Steinhardt [this message]
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=apayIuf9kXQcQPvS@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=niko.lecam@gmail.com \
--cc=peff@peff.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox