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

[PATCH 2/3] diffcore-pickaxe: fix leaks in "log -S<block>" and "log -G<pattern>"

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 5, 2013, 04:45 UTC
Message-ID
<1365137126-21659-2-git-send-email-gitster@pobox.com>
In-Reply-To
<1365137126-21659-1-git-send-email-gitster@pobox.com>

The diff_grep() and has_changes() functions had early return codepaths for unmerged filepairs, which simply returned 0. When we taught textconv filter to them, one was ignored and continued to return early without freeing the result filtered by textconv, and the other had a failed attempt to fix, which allowed the planned return value 0 to be overwritten by a bogus call to contains().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diffcore-pickaxe.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index bfaabab..cadb071 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -99,9 +99,10 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
 
 	if (!DIFF_FILE_VALID(p->one)) {
 		if (!DIFF_FILE_VALID(p->two))
-			return 0; /* ignore unmerged */
-		/* created "two" -- does it have what we are looking for? */
-		hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
+			hit = 0; /* ignore unmerged */
+		else
+			/* created "two" -- does it have what we are looking for? */
+			hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
 	} else if (!DIFF_FILE_VALID(p->two)) {
 		/* removed "one" -- did it have what we are looking for? */
 		hit = !regexec(regexp, mf1.ptr, 1, &regmatch, 0);
@@ -229,8 +230,9 @@ static int has_changes(struct diff_filepair *p, struct diff_options *o,
 	if (!DIFF_FILE_VALID(p->one)) {
 		if (!DIFF_FILE_VALID(p->two))
 			ret = 0; /* ignore unmerged */
-		/* created */
-		ret = contains(&mf2, o, regexp, kws) != 0;
+		else
+			/* created */
+			ret = contains(&mf2, o, regexp, kws) != 0;
 	}
 	else if (!DIFF_FILE_VALID(p->two)) /* removed */
 		ret = contains(&mf1, o, regexp, kws) != 0;
-- 
1.8.2-588-gbf1c992
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 27 in “[BUG] git log -S not respecting --no-textconv”
  1. Matthieu MoyApr 4, 2013
  2. 1/2 diffcore-pickaxe: respect --no-textconvSimon Ruderich, Apr 4, 2013
  3. Matthieu MoyApr 4, 2013
  4. Jeff KingApr 4, 2013
  5. Junio C HamanoApr 4, 2013
  6. Jeff KingApr 4, 2013
  7. Junio C HamanoApr 4, 2013
  8. 1/3 diffcore-pickaxe: remove unnecessary call to get_textconv()Simon Ruderich, Apr 4, 2013
  9. Junio C HamanoApr 4, 2013
  10. Junio C HamanoApr 4, 2013
  11. Jeff KingApr 4, 2013
  12. Junio C HamanoApr 4, 2013
  13. Simon RuderichApr 5, 2013
  14. 2/3 diffcore-pickaxe: remove fill_one()Simon Ruderich, Apr 4, 2013
  15. Jeff KingApr 5, 2013
  16. Junio C HamanoApr 5, 2013
  17. 1/3 diffcore-pickaxe: port optimization from has_changes() to diff_grep()Junio C Hamano, Apr 5, 2013
  18. 2/3 diffcore-pickaxe: fix leaks in "log -S<block>" and "log -G<pattern>"Junio C Hamano, Apr 5, 2013
  19. 3/3 diffcore-pickaxe: unify setup and teardown code between log -S/-GJunio C Hamano, Apr 5, 2013
  20. Jeff KingApr 5, 2013
  21. Junio C HamanoApr 5, 2013
  22. Jeff KingApr 5, 2013
  23. Junio C HamanoApr 5, 2013
  24. 3/3 diffcore-pickaxe: respect --no-textconvSimon Ruderich, Apr 4, 2013
  25. Matthieu MoyApr 5, 2013
  26. 3/3 diffcore-pickaxe: respect --no-textconvSimon Ruderich, Apr 5, 2013
  27. Junio C HamanoApr 5, 2013

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.