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

Re: [PATCH v2 1/2] builtin/gc: fix condition for whether to write commit graphs

From
Toon Claes <toon@iotcl.com>
Date
Dec 11, 2025, 14:16 UTC
Message-ID
<87ecp1gl2z.fsf@iotcl.com>
In-Reply-To
<20251211-odb-related-fixes-v2-1-bdf875ce51fc@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 50 quoted lines
> The root cause of this memory leak is our use of `commit_list_append()`.
> This function expects as parameters the item to append and the _tail_ of
> the list to append. This tail will then be overwritten with the new tail
> of the list so that it can be used in subsequent calls. But we call it
> with `commit_list_append(parent->item, &stack)`, so we end up losing
> everything but the new item.
>
> This issue only surfaces when counting merge commits. Next to being a
> memory leak, it also shows that we're in fact miscounting as we only
> respect children of the last parent. All previous parents are discarded,
> so their children will be disregarded unless they are hit via another
> reference.
>
> While crafting a test case for the issue I was puzzled that I couldn't
> establish the proper border at which the auto-condition would be
> fulfilled. As it turns out, there's another bug: if an object is at the
> tip of any reference we don't mark it as seen. Consequently, if it is
> reachable via any other reference, we'd count that object twice.
>
> Fix both of these bugs so that we properly count objects without leaking
> any memory.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/gc.c           |  8 +++++---
>  t/t7900-maintenance.sh | 25 +++++++++++++++++++++++++
>  2 files changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 92c6e7b954..17ff68cbd9 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1130,8 +1130,10 @@ static int dfs_on_ref(const struct reference *ref, void *cb_data)
>  		return 0;
>  
>  	commit = lookup_commit(the_repository, maybe_peeled);
> -	if (!commit)
> +	if (!commit || commit->object.flags & SEEN)
>  		return 0;
> +	commit->object.flags |= SEEN;
> +
>  	if (repo_parse_commit(the_repository, commit) ||
>  	    commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
>  		return 0;
> @@ -1141,7 +1143,7 @@ static int dfs_on_ref(const struct reference *ref, void *cb_data)
>  	if (data->num_not_in_graph >= data->limit)
>  		return 1;
>  
> -	commit_list_append(commit, &stack);
> +	commit_list_insert(commit, &stack);

commit_list_insert() prepends the commit to the beginning of the list, while commit_list_append() appends it at the end. Because the list is only used for counting, we don't care about the order. So this fix looks good to me.

I also approve the other changes in this series.
-- 
Cheers,
Toon
Previous: Patrick SteinhardtNext: Karthik Nayak
Message 15 of 26 in “Some random object database related fixes”
  1. 0/3 Some random object database related fixesPatrick Steinhardt, Dec 5, 2025
  2. 1/3 builtin/repack: fix geometric repacks with promisor remotesPatrick Steinhardt, Dec 5, 2025
  3. Justin ToblerDec 10, 2025
  4. Patrick SteinhardtDec 11, 2025
  5. 2/3 builtin/gc: fix condition for whether to write commit graphsPatrick Steinhardt, Dec 5, 2025
  6. Justin ToblerDec 10, 2025
  7. Patrick SteinhardtDec 11, 2025
  8. 3/3 odb: properly close sources before freeing themPatrick Steinhardt, Dec 5, 2025
  9. Eric SunshineDec 5, 2025
  10. Patrick SteinhardtDec 6, 2025
  11. Eric SunshineDec 6, 2025
  12. Patrick SteinhardtDec 6, 2025
  13. 0/2 Some random object database related fixesPatrick Steinhardt, Dec 11, 2025
  14. 1/2 builtin/gc: fix condition for whether to write commit graphsPatrick Steinhardt, Dec 11, 2025
  15. Toon ClaesDec 11, 2025
  16. Karthik NayakJan 6, 2026
  17. Patrick SteinhardtJan 6, 2026
  18. Karthik NayakJan 6, 2026
  19. 2/2 odb: properly close sources before freeing themPatrick Steinhardt, Dec 11, 2025
  20. Justin ToblerDec 12, 2025
  21. Karthik NayakJan 6, 2026
  22. 0/2 Some random object database related fixesPatrick Steinhardt, Jan 6, 2026
  23. 1/2 builtin/gc: fix condition for whether to write commit graphsPatrick Steinhardt, Jan 6, 2026
  24. 2/2 odb: properly close sources before freeing themPatrick Steinhardt, Jan 6, 2026
  25. Karthik NayakJan 6, 2026
  26. Junio C HamanoJan 7, 2026

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.