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

Re: [PATCH v2] delta-islands: free island-related data after use

From
Jeff King <peff@peff.net>
Date
Nov 22, 2022, 20:22 UTC
Message-ID
<Y30vf76mdrSv4We4@coredump.intra.peff.net>
In-Reply-To
<20221117230658.M516129@dcvr>
On Thu, Nov 17, 2022 at 11:06:58PM +0000, Eric Wong wrote:
Show 7 quoted lines
> Aside from that, v2 below still frees the regex memory early on
> in the hopes deduplicate_islands() can reuse some of the freed
> regexp memory.
> 
> Anyways, here's v2, which seems to work.  I'm still trying to
> figure out SATA errors+resets after replacing a CMOS battery,
> but I really hope this patch isn't the cause.

This looks OK to me, though I think it would have been easier to review split into two patches (one pushing the globals into local variables and the other adding the freeing).

Two small notes:
Show 12 quoted lines
>  void load_delta_islands(struct repository *r, int progress)
>  {
> +	struct island_load_data ild = { 0 };
> +
>  	island_marks = kh_init_oid_map();
> -	remote_islands = kh_init_str();
>  
> -	git_config(island_config_callback, NULL);
> -	for_each_ref(find_island_for_ref, NULL);
> -	deduplicate_islands(r);
> +	git_config(island_config_callback, &ild);
> +	ild.remote_islands = kh_init_str();

The initialization of the remote_islands khash is now moved after we read the config. That's OK, because our callback doesn't read it, but it's not immediately obvious without going back to check the callback.

Splitting it into:
  struct island_load_data {
	kh_str_t *remote_islands;
	struct island_regexes regexes {
		regex_t *rx;
		size_t nr;
		size_t alloc;
	};
  };
lets you pass:
  git_config(island_config_callback, &ild.regexes);

which makes it clear that the khash part isn't touched. But you still get to pass the whole &ild around later. Of course that's all going through a void pointer, so you're praying that the callback expects the right type anyway. ;)

And with your code we'd hopefully notice the problem right away since the khash pointer is NULL. So it might not be that big a deal.

> +	for_each_ref(find_island_for_ref, &ild);
> +	free_config_regexes(&ild);
> +	deduplicate_islands(ild.remote_islands, r);
> +	free_remote_islands(ild.remote_islands);

Here we free the regexes, but they're pointing to garbage memory still. But since we pass just the remote_islands part of the struct to those functions, we know they can't look at the garbage regexes. Good.

I'd have said it ought to be two separate variables, but the for_each_ref() callback forces your hand there.

-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Jeff King
Message 5 of 9 in “delta-islands: free island-related data after use”
  1. delta-islands: free island-related data after useEric Wong, Nov 16, 2022
  2. Ævar Arnfjörð BjarmasonNov 16, 2022
  3. delta-islands: free island-related data after useEric Wong, Nov 17, 2022
  4. Ævar Arnfjörð BjarmasonNov 18, 2022
  5. Jeff KingNov 22, 2022
  6. Jeff KingNov 16, 2022
  7. pack-objects memory use observations [was: [PATCH] delta-islands: free island-related data after use]Eric Wong, Feb 1, 2023
  8. Eric WongFeb 1, 2023
  9. Jeff KingFeb 2, 2023

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.