From: Glen Choo <chooglen@google.com>
To: "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Glen Choo via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, Taylor Blau <me@ttaylorr.com>
Subject: Re: [PATCH v2] object-file: use real paths when adding alternates
Date: Wed, 23 Nov 2022 16:50:02 -0800 [thread overview]
Message-ID: <kl6lwn7lch1h.fsf@chooglen-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <Y30onDTUFmAezkSl@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
>> Doesn't this leak? I've just skimmed strbuf_realpath_1() but e.g. in the
>> "REALPATH_MANY_MISSING" case it'll have allocated the "resolved" (the
>> &tmp you pass in here) and then "does a "goto error_out".
>>
>> It then *resets* the strbuf, but doesn't release it, assuming that
>> you're going to pass it in again. So in that case we'd leak here, no?
>>
>> I.e. a NULL return value from strbuf_realpath() doesn't mean that it
>> didn't allocate in the scratch area passed to it, so we need to
>> strbuf_release(&tmp) here too.
>
> We don't use MANY_MISSING in this code path, but I didn't read
> strbuf_realpath_1() carefully enough to see if that is the only case.
> But regardless, I think it is a bug in strbuf_realpath(). All of the
> strbuf functions generally try to leave a buffer untouched on error.
>
> So IMHO we would want a preparatory patch with s/reset/release/ in that
> function, which better matches the intent (we might be freeing an
> allocated buffer, but that's OK from the caller perspective).
Is that always OK? I would think that we'd do something closer to
strbuf_getcwd():
int strbuf_getcwd(struct strbuf *sb)
{
size_t oldalloc = sb->alloc;
/* ... */
if (oldalloc == 0)
strbuf_release(sb);
else
strbuf_reset(sb);
}
i.e. if the caller passed in a strbuf with allocated contents, they're
responsible for free()-ing it, otherwise we free() it. That does fix the
leak in this patch, but I don't feel strongly enough about changing
strbuf_realpath() to do it now, so I'll do without the change for now.
next prev parent reply other threads:[~2022-11-24 0:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-17 17:31 [PATCH] object-file: use real paths when adding alternates Glen Choo via GitGitGadget
2022-11-17 18:47 ` Jeff King
2022-11-17 19:41 ` Ævar Arnfjörð Bjarmason
2022-11-17 21:57 ` Jeff King
2022-11-17 22:03 ` Taylor Blau
2022-11-18 0:00 ` Glen Choo
2022-11-17 21:54 ` Taylor Blau
2022-11-21 23:49 ` [PATCH v2] " Glen Choo via GitGitGadget
2022-11-22 0:56 ` Ævar Arnfjörð Bjarmason
2022-11-22 19:53 ` Jeff King
2022-11-24 0:50 ` Glen Choo [this message]
2022-11-24 1:06 ` Jeff King
2022-11-24 0:20 ` Glen Choo
2022-11-22 19:40 ` Jeff King
2022-11-24 0:55 ` [PATCH v3] " Glen Choo via GitGitGadget
2022-11-24 1:08 ` Jeff King
2022-11-25 6:51 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=kl6lwn7lch1h.fsf@chooglen-macbookpro.roam.corp.google.com \
--to=chooglen@google.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=me@ttaylorr.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).