bisect: fix off-by-one error in `best_bisection_sorted()`
[gitweb.git] / bisect.c
index 2f4321767aec174ca57b4d89a4ae88926970bb67..b1941505b236b5cb56ea7fe757dab215dcf2bb07 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -226,10 +226,11 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
                add_name_decoration(DECORATION_NONE, buf.buf, obj);
 
                p->item = array[i].commit;
-               p = p->next;
+               if (i < cnt - 1)
+                       p = p->next;
        }
-       if (p)
-               p->next = NULL;
+       free_commit_list(p->next);
+       p->next = NULL;
        strbuf_release(&buf);
        free(array);
        return list;