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

[PATCH] ref-filter: plug memory leak in reach_filter()

From
René Scharfe <l.s.r@web.de>
Date
Sep 26, 2020, 08:37 UTC
Message-ID
<d9922bbe-4e34-45fe-66a5-d7b5bf42117a@web.de>

21bf933928 (ref-filter: allow merged and no-merged filters, 2020-09-15) added an early return to reach_filter(). Avoid leaking the memory of a then unused array by postponing its allocation until we know we need it.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 ref-filter.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/ref-filter.c b/ref-filter.c
index 5550a0d34c..e0b8cd3ed8 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2239,12 +2239,14 @@ static void reach_filter(struct ref_array *array,
 {
 	struct rev_info revs;
 	int i, old_nr;
-	struct commit **to_clear = xcalloc(sizeof(struct commit *), array->nr);
+	struct commit **to_clear;
 	struct commit_list *cr;

 	if (!check_reachable)
 		return;

+	to_clear = xcalloc(sizeof(struct commit *), array->nr);
+
 	repo_init_revisions(the_repository, &revs, NULL);

 	for (i = 0; i < array->nr; i++) {
--
2.28.0
Next: Aaron Lipman
Message 1 of 3 in “ref-filter: plug memory leak in reach_filter()”
  1. ref-filter: plug memory leak in reach_filter()René Scharfe, Sep 26, 2020
  2. Aaron LipmanSep 26, 2020
  3. Junio C HamanoSep 26, 2020

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.