From 88ff684dd54f2a4793387f7162357005a4777ff2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 4 Apr 2013 21:03:21 -0700 Subject: [PATCH] diffcore-pickaxe: fix leaks in "log -S" and "log -G" 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 --- diffcore-pickaxe.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index bfaababbe5..cadb071a44 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, ®match, 0); + hit = 0; /* ignore unmerged */ + else + /* created "two" -- does it have what we are looking for? */ + hit = !regexec(regexp, mf2.ptr, 1, ®match, 0); } else if (!DIFF_FILE_VALID(p->two)) { /* removed "one" -- did it have what we are looking for? */ hit = !regexec(regexp, mf1.ptr, 1, ®match, 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; -- 2.11.4.GIT