Re: [PATCH v4] fetch: advertise fetched refs when backfilling tags
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Oct 23, 2026, 22:12 UTC
- Message-ID
- <CAOLa=ZQQwYyufEWm_cS3o9t7SDfCwDSMKU7rsnctCojc4=FoGg@mail.gmail.com>
- In-Reply-To
- <CAOLa=ZSnhGwBevejqv1Nzw92q6tt6zMDM528qFb7xqY1-6mxrg@mail.gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 58 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
>
>> On Fri, Oct 23, 2026 at 03:58:11AM -0700, Karthik Nayak wrote:
>>> Patrick Steinhardt <ps@pks.im> writes:
>>> > on thu, oct 22, 2026 at 11:00:16pm +0200, karthik nayak wrote:
>>> >> diff --git a/builtin/fetch.c b/builtin/fetch.c
>>> >> index b2decc6cfd..9867e8c2ef 100644
>>> >> --- a/builtin/fetch.c
>>> >> +++ b/builtin/fetch.c
>>> >> @@ -1697,9 +1699,30 @@ static int backfill_tags(struct display_state *display_state,
>>> >> transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
>>> >> transport_set_option(transport, TRANS_OPT_DEPTH, "0");
>>> >> transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
>>> >> +
>>> >> + /*
>>> >> + * References fetched before the tag backfill aren't yet committed
>>> >> + * to disk, so negotiation cannot discover them. Advertise them to
>>> >> + * the server, so that it does not re-send objects we already have.
>>> >> + */
>>> >> + if (fetched_tips && fetched_tips->nr && transport->smart_options) {
>>> >> + struct oid_array **include_tips =
>>> >> + &transport->smart_options->negotiation_include_tips;
>>> >> + if (!*include_tips)
>>> >> + *include_tips = to_free = xcalloc(1, sizeof(**include_tips));
>>> >> + for (size_t i = 0; i < fetched_tips->nr; i++)
>>> >> + oid_array_append(*include_tips, &fetched_tips->oid[i]);
>>> >> + }
>>> >
>>> > Curious. Why don't we have `struct oid_array` as a local variable and
>>> > then simply `transport->smart_options->negotiation_include_tips =
>>> > &extra_tips`?
>>> >
>>>
>>> Because `transport->smart_options->negotiation_include_tips` may already
>>> be set when this function is called, so we only free it when we are the
>>> exclusive setters of the field.
>>
>> Ah, okay. But if it was set already, what does it contain? And is it
>> okay that we essentially leak the fetched tips to our callers now if it
>> was set?
>>
>> Patrick
>
> So it is set when the user uses the '--negotiation-include' option and
> provides their own tips.
>
> When I wrote this code, I didn't include the free'ing that you see here.
> But it triggered the leak sanitizer for 't5509-fetch-push-namespaces'. I
> assumed it was due to my code and added this logic, without digging too
> much into why my path specifically triggered it.
>
> So, the transport does free the `negotiation_include_tips`, but only for
> transports which supports smart_options. Meaning, we should only add the
> tips for transports with smart options. As the other route doesn't use
> it and as such doesn't free the array.
>
> Thanks for the pushback, I'll fix it up in the next version.
>I need to not send emails in the middle of the night. Seems like I'm still wrong here.
The issue seems to be that for 't5509-fetch-push-namespaces' the tests which trigger the leaks are those which use a remote helper and seems like the transport with remote-helpers don't clean up correctly. So while they support smart options, they don't do the necessary cleanup.
Seems like an existing bug, will add a precursor commit to fix it.
Karthik