Skip to content

Commit

Permalink
diffcore-pickaxe: fix leaks in "log -S<block>" and "log -G<pattern>"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Apr 5, 2013
1 parent ebb7226 commit 88ff684
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions diffcore-pickaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 88ff684

Please sign in to comment.