From: Karthik Nayak Date: Fri, 23 Oct 2026 22:01:01 GMT Subject: Re: [PATCH v4] fetch: advertise fetched refs when backfilling tags Message-ID: In-Reply-To: Patrick Steinhardt writes: > On Fri, Oct 23, 2026 at 03:58:11AM -0700, Karthik Nayak wrote: >> Patrick Steinhardt 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.