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

[PATCH 2/2] diff-no-index: release prefixed filenames

From
René Scharfe <l.s.r@web.de>
Date
Sep 6, 2022, 12:31 UTC
Message-ID
<df5f8305-79d5-2c12-bdf0-961428c0bdd1@web.de>
In-Reply-To
<xmqq8rmx1saz.fsf@gitster.g>

Callers of prefix_filename() are responsible for freeing its result. Remember them and release them to appease leak checkers.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 diff-no-index.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index a3683d8a04..35809f26d7 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -245,6 +245,7 @@ int diff_no_index(struct rev_info *revs,
 	int i, no_index;
 	int ret = 1;
 	const char *paths[2];
+	char *to_free[2] = { 0 };
 	struct strbuf replacement = STRBUF_INIT;
 	const char *prefix = revs->prefix;
 	struct option no_index_options[] = {
@@ -274,7 +275,7 @@ int diff_no_index(struct rev_info *revs,
 			 */
 			p = file_from_standard_input;
 		else if (prefix)
-			p = prefix_filename(prefix, p);
+			p = to_free[i] = prefix_filename(prefix, p);
 		paths[i] = p;
 	}

@@ -308,6 +309,8 @@ int diff_no_index(struct rev_info *revs,
 	ret = diff_result_code(&revs->diffopt, 0);

 out:
+	for (i = 0; i < 2; i++)
+		free(to_free[i]);
 	strbuf_release(&replacement);
 	return ret;
 }
--
2.37.2
Previous: René ScharfeNext: Johannes Schindelin
Message 7 of 17 in “unleak paths allocated in "diff --no-index"”
  1. unleak paths allocated in "diff --no-index"Junio C Hamano, Sep 2, 2022
  2. diff --no-index: unleak paths[] elementsJunio C Hamano, Sep 2, 2022
  3. René ScharfeSep 3, 2022
  4. Junio C HamanoSep 5, 2022
  5. 1/2 diff-no-index: release strbuf on queue errorRené Scharfe, Sep 6, 2022
  6. René ScharfeSep 7, 2022
  7. 2/2 diff-no-index: release prefixed filenamesRené Scharfe, Sep 6, 2022
  8. Johannes SchindelinSep 7, 2022
  9. René ScharfeSep 7, 2022
  10. 1/2 diff-no-index: release strbuf on queue errorRené Scharfe, Sep 7, 2022
  11. 2/2 diff-no-index: release prefixed filenamesRené Scharfe, Sep 7, 2022
  12. 3/2 diff-no-index: simplify argv index calculationRené Scharfe, Sep 7, 2022
  13. Junio C HamanoSep 7, 2022
  14. Johannes SchindelinSep 5, 2022
  15. Ævar Arnfjörð BjarmasonSep 5, 2022
  16. Johannes SchindelinSep 7, 2022
  17. Ævar Arnfjörð BjarmasonSep 7, 2022

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.