Skip to content

Commit 88ff684

Browse files
committed
diffcore-pickaxe: fix leaks in "log -S<block>" and "log -G<pattern>"
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 <[email protected]>
1 parent ebb7226 commit 88ff684

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

diffcore-pickaxe.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
9999

100100
if (!DIFF_FILE_VALID(p->one)) {
101101
if (!DIFF_FILE_VALID(p->two))
102-
return 0; /* ignore unmerged */
103-
/* created "two" -- does it have what we are looking for? */
104-
hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
102+
hit = 0; /* ignore unmerged */
103+
else
104+
/* created "two" -- does it have what we are looking for? */
105+
hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
105106
} else if (!DIFF_FILE_VALID(p->two)) {
106107
/* removed "one" -- did it have what we are looking for? */
107108
hit = !regexec(regexp, mf1.ptr, 1, &regmatch, 0);
@@ -229,8 +230,9 @@ static int has_changes(struct diff_filepair *p, struct diff_options *o,
229230
if (!DIFF_FILE_VALID(p->one)) {
230231
if (!DIFF_FILE_VALID(p->two))
231232
ret = 0; /* ignore unmerged */
232-
/* created */
233-
ret = contains(&mf2, o, regexp, kws) != 0;
233+
else
234+
/* created */
235+
ret = contains(&mf2, o, regexp, kws) != 0;
234236
}
235237
else if (!DIFF_FILE_VALID(p->two)) /* removed */
236238
ret = contains(&mf1, o, regexp, kws) != 0;

0 commit comments

Comments
 (0)