Skip to content

Commit 2e9fdc7

Browse files
avargitster
authored andcommitted
bisect: fix a regression causing a segfault
In 7c11718 ("bisect: fix off-by-one error in `best_bisection_sorted()`", 2017-11-05) the more careful logic dealing with freeing p->next in 50e62a8 ("rev-list: implement --bisect-all", 2007-10-22) was removed. Restore the more careful check to avoid segfaulting. Ideally this would come with a test case, but we don't have steps to reproduce this, only a backtrace from gdb pointing to this being the issue. Reported-by: Yasushi SHOJI <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Acked-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f4e45cb commit 2e9fdc7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

bisect.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
229229
if (i < cnt - 1)
230230
p = p->next;
231231
}
232-
free_commit_list(p->next);
233-
p->next = NULL;
232+
if (p) {
233+
free_commit_list(p->next);
234+
p->next = NULL;
235+
}
234236
strbuf_release(&buf);
235237
free(array);
236238
return list;

0 commit comments

Comments
 (0)