Git fork

bisect: address Coverity warning about potential double free

Coverity has started to warn about a potential double-free in
`find_bisection()`. This warning is triggered because we may modify the
list head of the passed-in `commit_list` in case it is an UNINTERESTING
commit, but still call `free_commit_list()` on the original variable
that points to the now-freed head in case where `do_find_bisection()`
returns a `NULL` pointer.

As far as I can see, this double free cannot happen in practice, as
`do_find_bisection()` only returns a `NULL` pointer when it was passed a
`NULL` input. So in order to trigger the double free we would have to
call `find_bisection()` with a commit list that only consists of
UNINTERESTING commits, but I have not been able to construct a case
where that happens.

Drop the `else` branch entirely as it seems to be a no-op anyway.
Another option might be to instead call `free_commit_list()` on `list`,
which is the modified version of `commit_list` and thus wouldn't cause a
double free. But as mentioned, I couldn't come up with any case where a
passed-in non-NULL list becomes empty, so this shouldn't be necessary.
And if it ever does become necessary we'd notice anyway via the leak
sanitizer.

Interestingly enough we did not have a single test exercising this
branch: all tests pass just fine even when replacing it with a call to
`BUG()`. Add a test that exercises it.

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
5f9f7faf c6c977e8

+5 -2
-2
bisect.c
··· 442 442 best->next = NULL; 443 443 } 444 444 *reaches = weight(best); 445 - } else { 446 - free_commit_list(*commit_list); 447 445 } 448 446 *commit_list = best; 449 447
+5
t/t6002-rev-list-bisect.sh
··· 308 308 test_cmp expect actual 309 309 ' 310 310 311 + test_expect_success '--bisect without any revisions' ' 312 + git rev-list --bisect HEAD..HEAD >out && 313 + test_must_be_empty out 314 + ' 315 + 311 316 test_done