From 2e9fdc795cb27725e6dda7f4ba78ec0d9553b36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Wed, 3 Jan 2018 18:48:52 +0000 Subject: bisect: fix a regression causing a segfault MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 7c117184d7 ("bisect: fix off-by-one error in `best_bisection_sorted()`", 2017-11-05) the more careful logic dealing with freeing p->next in 50e62a8e70 ("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 Signed-off-by: Ævar Arnfjörð Bjarmason Acked-by: Martin Ågren Signed-off-by: Junio C Hamano --- bisect.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bisect.c b/bisect.c index 3756f127b0..87e4dee16d 100644 --- a/bisect.c +++ b/bisect.c @@ -229,8 +229,10 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n if (i < cnt - 1) p = p->next; } - free_commit_list(p->next); - p->next = NULL; + if (p) { + free_commit_list(p->next); + p->next = NULL; + } strbuf_release(&buf); free(array); return list; -- cgit v1.2.3