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

[PATCH] diff-lib: plug minor memory leaks in do_diff_cache()

From
René Scharfe <l.s.r@web.de>
Date
Nov 14, 2020, 18:37 UTC
Message-ID
<80fb4a2a-992f-7d3b-9413-5059da3a8f01@web.de>

do_diff_cache() builds a struct rev_info to hand to diff_cache() from scratch by initializing it using repo_init_revisions() and then replacing its diffopt and prune_data members.

The diffopt member is initialized to a heap-allocated list of options, though. Release it using diff_setup_done() before overwriting it.

The initial value of the prune_data member doesn't need to be released, but the copy created using copy_pathspec() does. Clear it after use.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 diff-lib.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/diff-lib.c b/diff-lib.c
index 082e249fc3..b73cc1859a 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -606,10 +606,12 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)

 	repo_init_revisions(opt->repo, &revs, NULL);
 	copy_pathspec(&revs.prune_data, &opt->pathspec);
+	diff_setup_done(&revs.diffopt);
 	revs.diffopt = *opt;

 	if (diff_cache(&revs, tree_oid, NULL, 1))
 		exit(128);
+	clear_pathspec(&revs.prune_data);
 	return 0;
 }

--
2.29.2
Next: Jeff King
Message 1 of 2 in “diff-lib: plug minor memory leaks in do_diff_cache()”
  1. diff-lib: plug minor memory leaks in do_diff_cache()René Scharfe, Nov 14, 2020
  2. Jeff KingNov 17, 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.