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

Re: [PATCH 2/4] shallow: fix memory leak when registering shallow roots

From
Jeff King <peff@peff.net>
Date
Nov 6, 2023, 17:21 UTC
Message-ID
<20231106172154.GB10414@coredump.intra.peff.net>
In-Reply-To
<137c150e358a8248200e0c7174a79358adb92e45.1699267422.git.ps@pks.im>
On Mon, Nov 06, 2023 at 11:45:57AM +0100, Patrick Steinhardt wrote:
Show 13 quoted lines
> --- a/shallow.c
> +++ b/shallow.c
> @@ -38,8 +38,10 @@ int register_shallow(struct repository *r, const struct object_id *oid)
>  
>  	oidcpy(&graft->oid, oid);
>  	graft->nr_parent = -1;
> -	if (commit && commit->object.parsed)
> +	if (commit && commit->object.parsed) {
> +		free_commit_list(commit->parents);
>  		commit->parents = NULL;
> +	}
>  	return register_commit_graft(r, graft, 0);
>  }

Good catch. When I've dealt with leaks around commit_lists in the past, one gotcha is that sometimes we've saved a pointer to the list elsewhere. But in this case it looks pretty clear that the parent list just goes away. So this patch is doing the right thing.

-Peff
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 of 9 in “Memory leak fixes”
  1. 0/4 Memory leak fixesPatrick Steinhardt, Nov 6, 2023
  2. 1/4 test-bloom: stop setting up Git directory twicePatrick Steinhardt, Nov 6, 2023
  3. Jeff KingNov 6, 2023
  4. 2/4 shallow: fix memory leak when registering shallow rootsPatrick Steinhardt, Nov 6, 2023
  5. Jeff KingNov 6, 2023
  6. 3/4 setup: refactor `upgrade_repository_format()` to have common exitPatrick Steinhardt, Nov 6, 2023
  7. 4/4 setup: fix leaking repository formatPatrick Steinhardt, Nov 6, 2023
  8. Jeff KingNov 6, 2023
  9. Junio C HamanoNov 7, 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.