git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 07/14] transport: stop needlessly copying bundle header references

From
Derrick Stolee <derrickstolee@github.com>
Date
Mar 2, 2022, 20:47 UTC
Message-ID
<dfa87840-e04b-972f-2468-f7f0afa0ad61@github.com>
In-Reply-To
<patch-07.14-be62ca89bf5-20220302T170718Z-avarab@gmail.com>
On 3/2/2022 12:10 PM, Ævar Arnfjörð Bjarmason wrote:
> Amend the logic added in fddf2ebe388 (transport: teach all vtables to
> allow fetch first, 2019-08-21) and save ourselves pointless work in
> fetch_refs_from_bundle().
...
Show 13 quoted lines
> +static void get_refs_from_bundle_inner(struct transport *transport)
> +{
> +	struct bundle_transport_data *data = transport->data;
> +
> +	if (data->fd > 0)
> +		close(data->fd);
> +	data->fd = read_bundle_header(transport->url, &data->header);
> +	if (data->fd < 0)
> +		die(_("could not read bundle '%s'"), transport->url);
> +
> +	transport->hash_algo = data->header.hash_algo;
> +}
> +

There are some subtle changes here that look odd, but it actually could present a behavior change.

Show 17 quoted lines
>  static struct ref *get_refs_from_bundle(struct transport *transport,
>  					int for_push,
>  					struct transport_ls_refs_options *transport_options)
> @@ -136,15 +149,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
>  	if (for_push)
>  		return NULL;
>  
> -	data->get_refs_from_bundle_called = 1;
> -
> -	if (data->fd > 0)
> -		close(data->fd);
> -	data->fd = read_bundle_header(transport->url, &data->header);
> -	if (data->fd < 0)
> -		die(_("could not read bundle '%s'"), transport->url);
> -
> -	transport->hash_algo = data->header.hash_algo;
> +	get_refs_from_bundle_inner(transport);

The implementation of get_refs_from_bundle_inner() is very close to these deleted lines, except you removed

	data->get_refs_from_bundle_called = 1;
and instead you added this change:
> -	if (!data->get_refs_from_bundle_called)
> -		get_refs_from_bundle(transport, 0, NULL);
> +	if (!data->get_refs_from_bundle_called++)
> +		get_refs_from_bundle_inner(transport);

So, this is checking to see if data->get_refs_from_bundle_called _was_ zero while also incrementing it. However, this member is an unsigned:1, so you're really toggling it on and off each time we reach this 'if' statement.

Using this "++" would still bother me stylistically, even if the type was uint64_t and the risk of overflow was minimal. If you put the "= 1" line into the inner method, then things go back to working as they did before.

Thanks, -Stolee

Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 12 of 37 in “tree-wide: small fixes for memory leaks”
  1. 00/14 tree-wide: small fixes for memory leaksÆvar Arnfjörð Bjarmason, Mar 2, 2022
  2. 01/14 index-pack: fix memory leaksÆvar Arnfjörð Bjarmason, Mar 2, 2022
  3. Derrick StoleeMar 2, 2022
  4. Ævar Arnfjörð BjarmasonMar 3, 2022
  5. 02/14 merge-base: free() allocated "struct commit **" listÆvar Arnfjörð Bjarmason, Mar 2, 2022
  6. 03/14 diff.c: free "buf" in diff_words_flush()Ævar Arnfjörð Bjarmason, Mar 2, 2022
  7. 05/14 remote-curl.c: free memory in cmd_main()Ævar Arnfjörð Bjarmason, Mar 2, 2022
  8. 04/14 urlmatch.c: add and use a *_release() functionÆvar Arnfjörð Bjarmason, Mar 2, 2022
  9. 06/14 bundle: call strvec_clear() on allocated strvecÆvar Arnfjörð Bjarmason, Mar 2, 2022
  10. 08/14 submodule--helper: fix trivial leak in module_add()Ævar Arnfjörð Bjarmason, Mar 2, 2022
  11. 07/14 transport: stop needlessly copying bundle header referencesÆvar Arnfjörð Bjarmason, Mar 2, 2022
  12. Derrick StoleeMar 2, 2022
  13. Ævar Arnfjörð BjarmasonMar 3, 2022
  14. 09/14 commit-graph: fix memory leak in misused string_list APIÆvar Arnfjörð Bjarmason, Mar 2, 2022
  15. 10/14 commit-graph: stop fill_oids_from_packs() progress on error and free()Ævar Arnfjörð Bjarmason, Mar 2, 2022
  16. 11/14 lockfile API users: simplify and don't leak "path"Ævar Arnfjörð Bjarmason, Mar 2, 2022
  17. 12/14 range-diff: plug memory leak in common invocationÆvar Arnfjörð Bjarmason, Mar 2, 2022
  18. 14/14 repository.c: free the "path cache" in repo_clear()Ævar Arnfjörð Bjarmason, Mar 2, 2022
  19. 13/14 range-diff: plug memory leak in read_patches()Ævar Arnfjörð Bjarmason, Mar 2, 2022
  20. Derrick StoleeMar 2, 2022
  21. 00/14 tree-wide: small fixes for memory leaksÆvar Arnfjörð Bjarmason, Mar 4, 2022
  22. 01/14 index-pack: fix memory leaksÆvar Arnfjörð Bjarmason, Mar 4, 2022
  23. 02/14 merge-base: free() allocated "struct commit **" listÆvar Arnfjörð Bjarmason, Mar 4, 2022
  24. 03/14 diff.c: free "buf" in diff_words_flush()Ævar Arnfjörð Bjarmason, Mar 4, 2022
  25. 04/14 urlmatch.c: add and use a *_release() functionÆvar Arnfjörð Bjarmason, Mar 4, 2022
  26. 05/14 remote-curl.c: free memory in cmd_main()Ævar Arnfjörð Bjarmason, Mar 4, 2022
  27. 06/14 bundle: call strvec_clear() on allocated strvecÆvar Arnfjörð Bjarmason, Mar 4, 2022
  28. 07/14 transport: stop needlessly copying bundle header referencesÆvar Arnfjörð Bjarmason, Mar 4, 2022
  29. Derrick StoleeMar 4, 2022
  30. 09/14 commit-graph: fix memory leak in misused string_list APIÆvar Arnfjörð Bjarmason, Mar 4, 2022
  31. 12/14 range-diff: plug memory leak in common invocationÆvar Arnfjörð Bjarmason, Mar 4, 2022
  32. 13/14 range-diff: plug memory leak in read_patches()Ævar Arnfjörð Bjarmason, Mar 4, 2022
  33. 11/14 lockfile API users: simplify and don't leak "path"Ævar Arnfjörð Bjarmason, Mar 4, 2022
  34. 14/14 repository.c: free the "path cache" in repo_clear()Ævar Arnfjörð Bjarmason, Mar 4, 2022
  35. 10/14 commit-graph: stop fill_oids_from_packs() progress on error and free()Ævar Arnfjörð Bjarmason, Mar 4, 2022
  36. 08/14 submodule--helper: fix trivial leak in module_add()Ævar Arnfjörð Bjarmason, Mar 4, 2022
  37. Derrick StoleeMar 4, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.