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

Re: [PATCH 0/5] PATH WALK III: Add 'git backfill' command

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 9, 2024, 00:34 UTC
Message-ID
<xmqqjzc9r8xs.fsf@gitster.g>
In-Reply-To
<xmqqy10qqwco.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
> It seems that the result of calling init_revisions() from backfill
> is leaked?
>
> https://github.com/git/git/actions/runs/12218430154/job/34083929479 
>
> I did not dig further but the below is from my local leaksanitizer
> run.

The attached patch seems to plug the leaks observed by your backfill tests. If you agree with the implementation of the change, you are welcome to squash it in. I may be missing a better mechanism in the path-walk API that I could use to plug the leaks, in which case, of course a fix using such a better mechanism is very much welcomed.

A few things I noticed about path-walk API during my poking are:
 - struct path_walk_info has PATH_WALK_INFO_INIT() macro, but not a
   matching path_walk_info_init() helper function to help initialize
   any heap-allocated instances.  In general, anything that requires
   _INIT() macro by definition wants to be initialized with more
   than nul-initialized (otherwise, it would be fine to leave it
   uninitialized in the BSS, clear with = {0} initialization on the
   stack), so lack of matching path_walk_info_init() raises an
   eyebrow.
 - struct path_walk_info seems to lack a destructor.  In general,
   anything complex enough to require initializer should have one.
 - lack of destructor for path_walk_info requires users to release
   resources held by "struct pattern_list" instance at pwi.pl; if we
   had a destructor, we wouldn't have 2 of the three leaks we had to
   fix here.
Thanks.
diff --git c/builtin/backfill.c w/builtin/backfill.c
index 225764f17e..1cf2df9303 100644
--- c/builtin/backfill.c
+++ w/builtin/backfill.c
@@ -92,8 +92,11 @@ static int do_backfill(struct backfill_context *ctx)
 
 	if (ctx->sparse) {
 		CALLOC_ARRAY(info.pl, 1);
-		if (get_sparse_checkout_patterns(info.pl))
+		if (get_sparse_checkout_patterns(info.pl)) {
+			clear_pattern_list(info.pl);
+			free(info.pl);
 			return error(_("problem loading sparse-checkout"));
+		}
 	}
 
 	repo_init_revisions(ctx->repo, &revs, "");
@@ -113,6 +116,11 @@ static int do_backfill(struct backfill_context *ctx)
 		download_batch(ctx);
 
 	clear_backfill_context(ctx);
+	release_revisions(&revs);
+	if (info.pl) {
+		clear_pattern_list(info.pl);
+		free(info.pl);
+	}
 	return ret;
 }
 
Previous: Junio C HamanoNext: Derrick Stolee via GitGitGadget
Message 17 of 39 in “PATH WALK III: Add 'git backfill' command”
  1. 0/5 PATH WALK III: Add 'git backfill' commandDerrick Stolee via GitGitGadget, Dec 6, 2024
  2. 1/5 backfill: add builtin boilerplateDerrick Stolee via GitGitGadget, Dec 6, 2024
  3. Patrick SteinhardtJan 16, 2025
  4. Junio C HamanoJan 16, 2025
  5. Derrick StoleeFeb 3, 2025
  6. 2/5 backfill: basic functionality and testsDerrick Stolee via GitGitGadget, Dec 6, 2024
  7. Patrick SteinhardtDec 16, 2024
  8. Derrick StoleeDec 18, 2024
  9. 3/5 backfill: add --batch-size=<n> optionDerrick Stolee via GitGitGadget, Dec 6, 2024
  10. Patrick SteinhardtDec 16, 2024
  11. Derrick StoleeDec 18, 2024
  12. Jean-Noël AVILAJan 19, 2025
  13. 4/5 backfill: add --sparse optionDerrick Stolee via GitGitGadget, Dec 6, 2024
  14. Patrick SteinhardtDec 16, 2024
  15. 5/5 backfill: assume --sparse when sparse-checkout is enabledDerrick Stolee via GitGitGadget, Dec 6, 2024
  16. Junio C HamanoDec 8, 2024
  17. Junio C HamanoDec 9, 2024
  18. 0/5 PATH WALK III: Add 'git backfill' commandDerrick Stolee via GitGitGadget, Dec 20, 2024
  19. 1/5 backfill: add builtin boilerplateDerrick Stolee via GitGitGadget, Dec 20, 2024
  20. 2/5 backfill: basic functionality and testsDerrick Stolee via GitGitGadget, Dec 20, 2024
  21. Patrick SteinhardtJan 16, 2025
  22. Derrick StoleeFeb 3, 2025
  23. 3/5 backfill: add --min-batch-size=<n> optionDerrick Stolee via GitGitGadget, Dec 20, 2024
  24. Patrick SteinhardtJan 16, 2025
  25. 4/5 backfill: add --sparse optionDerrick Stolee via GitGitGadget, Dec 20, 2024
  26. Patrick SteinhardtJan 16, 2025
  27. Derrick StoleeFeb 3, 2025
  28. 5/5 backfill: assume --sparse when sparse-checkout is enabledDerrick Stolee via GitGitGadget, Dec 20, 2024
  29. Patrick SteinhardtJan 16, 2025
  30. Junio C HamanoJan 17, 2025
  31. 0/5 PATH WALK III: Add 'git backfill' commandDerrick Stolee via GitGitGadget, Feb 3, 2025
  32. 1/5 backfill: add builtin boilerplateDerrick Stolee via GitGitGadget, Feb 3, 2025
  33. 2/5 backfill: basic functionality and testsDerrick Stolee via GitGitGadget, Feb 3, 2025
  34. 3/5 backfill: add --min-batch-size=<n> optionDerrick Stolee via GitGitGadget, Feb 3, 2025
  35. 4/5 backfill: add --sparse optionDerrick Stolee via GitGitGadget, Feb 3, 2025
  36. 5/5 backfill: assume --sparse when sparse-checkout is enabledDerrick Stolee via GitGitGadget, Feb 3, 2025
  37. Junio C HamanoFeb 4, 2025
  38. Patrick SteinhardtFeb 5, 2025
  39. Junio C HamanoFeb 5, 2025

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.