Git fork

bisect: fix various cases where we leak commit list items

There are various cases where we leak commit list items because we
evict items from the list, but don't free them. Plug those.

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
c1e98f90 2b7706aa

+23 -8
+22 -8
bisect.c
··· 442 442 best->next = NULL; 443 443 } 444 444 *reaches = weight(best); 445 + } else { 446 + free_commit_list(*commit_list); 445 447 } 448 + *commit_list = best; 449 + 446 450 free(weights); 447 - *commit_list = best; 448 451 clear_commit_weight(&commit_weight); 449 452 } 450 453 ··· 557 560 tried = &list->next; 558 561 } else { 559 562 if (!show_all) { 560 - if (!skipped_first || !*skipped_first) 563 + if (!skipped_first || !*skipped_first) { 564 + free_commit_list(next); 565 + free_commit_list(filtered); 561 566 return list; 567 + } 562 568 } else if (skipped_first && !*skipped_first) { 563 569 /* This means we know it's not skipped */ 564 570 *skipped_first = -1; ··· 614 620 615 621 static struct commit_list *skip_away(struct commit_list *list, int count) 616 622 { 617 - struct commit_list *cur, *previous; 623 + struct commit_list *cur, *previous, *result = list; 618 624 int prn, index, i; 619 625 620 626 prn = get_prn(count); ··· 626 632 for (i = 0; cur; cur = cur->next, i++) { 627 633 if (i == index) { 628 634 if (!oideq(&cur->item->object.oid, current_bad_oid)) 629 - return cur; 630 - if (previous) 631 - return previous; 632 - return list; 635 + result = cur; 636 + else if (previous) 637 + result = previous; 638 + else 639 + result = list; 640 + break; 633 641 } 634 642 previous = cur; 635 643 } 636 644 637 - return list; 645 + for (cur = list; cur != result; ) { 646 + struct commit_list *next = cur->next; 647 + free(cur); 648 + cur = next; 649 + } 650 + 651 + return result; 638 652 } 639 653 640 654 static struct commit_list *managed_skipped(struct commit_list *list,
+1
t/t6030-bisect-porcelain.sh
··· 9 9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 10 10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 11 11 12 + TEST_PASSES_SANITIZE_LEAK=true 12 13 . ./test-lib.sh 13 14 14 15 add_line_into_file()