From: Jacob Keller <jacob.e.keller@intel.com>
To: Jeff King <peff@peff.net>, Lidong Yan <yldhome2d2@gmail.com>
Cc: <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>,
Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH v2] reflog: close leak of reflog expire entry
Date: Thu, 10 Jul 2025 08:54:01 -0700 [thread overview]
Message-ID: <6fa10a33-7434-434a-9ef3-02fbaf21e1e1@intel.com> (raw)
In-Reply-To: <20250710034241.GA2057509@coredump.intra.peff.net>
[-- Attachment #1.1: Type: text/plain, Size: 2237 bytes --]
On 7/9/2025 8:42 PM, Jeff King wrote:
> On Thu, Jul 10, 2025 at 11:00:38AM +0800, Lidong Yan wrote:
>
>> In builtin/reflog.c, we have code like
>>
>> ---
>> for (i = 0; i < argc; i++) {
>> char *ref;
>> struct expire_reflog_policy_cb cb = { .opts = opts };
>>
>> if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) {
>> status |= error(_("reflog could not be found: '%s'"), argv[i]);
>> continue;
>> }
>> reflog_expire_options_set_refname(&cb.opts, ref);
>> status |= refs_reflog_expire(get_main_ref_store(the_repository),
>> ref, flags,
>> reflog_expiry_prepare,
>> should_prune_fn,
>> reflog_expiry_cleanup,
>> &cb);
>> free(ref);
>> }
>> + reflog_clear_expire_config(&opts);
>> ---
>>
>> I think allowing reblog_expiry_cleanup() to free all opt->entries might
>> cause reblog_expire_options_set_refname() to behave incorrectly.
>
> Hmm, yeah. We are calling this in a loop, so we'd want the config to
> persist until the loop ends. I didn't test, but I'd guess that:
>
> git -c 'gc.refs/heads/*.reflogExpire=now' \
> reflog expire refs/heads/foo refs/heads/bar
>
> would apply the config for "foo" but not for "bar". So I think
> reflog_expiry_cleanup() has to just clean up per-traversal data, not the
> config.
>
> So the call at the end here looks reasonable, but the call in
> reflog_expiry_cleanup() is wrong. I guess it was trying to cover the
> call in reflog_expire_condition(). That probably just needs a manual:
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 845876ff02..37f5437365 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -346,6 +346,7 @@ static int reflog_expire_condition(struct gc_config *cfg UNUSED)
> count_reflog_entries, &data);
>
> reflog_expiry_cleanup(&data.policy);
> + reflog_clear_expire_config(&data.policy);
> return data.count >= data.limit;
Ya, you're right. I just thought the reflog_expiry_cleanup would only be
called by this function. It did pass the tests... I'll see if I can add
a test case covering this since its caused a bit more trouble than I
thought it would.
> }
>
>
> -Peff
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
prev parent reply other threads:[~2025-07-10 15:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 23:41 [PATCH v2] reflog: close leak of reflog expire entry Jacob Keller
2025-07-10 3:00 ` Lidong Yan
2025-07-10 3:42 ` Jeff King
2025-07-10 15:54 ` Jacob Keller [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=6fa10a33-7434-434a-9ef3-02fbaf21e1e1@intel.com \
--to=jacob.e.keller@intel.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
--cc=peff@peff.net \
--cc=yldhome2d2@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).