Skip to content

Commit c1e98f9

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b7706a commit c1e98f9

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

bisect.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,12 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
442442
best->next = NULL;
443443
}
444444
*reaches = weight(best);
445+
} else {
446+
free_commit_list(*commit_list);
445447
}
446-
free(weights);
447448
*commit_list = best;
449+
450+
free(weights);
448451
clear_commit_weight(&commit_weight);
449452
}
450453

@@ -557,8 +560,11 @@ struct commit_list *filter_skipped(struct commit_list *list,
557560
tried = &list->next;
558561
} else {
559562
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);
561566
return list;
567+
}
562568
} else if (skipped_first && !*skipped_first) {
563569
/* This means we know it's not skipped */
564570
*skipped_first = -1;
@@ -614,7 +620,7 @@ static int sqrti(int val)
614620

615621
static struct commit_list *skip_away(struct commit_list *list, int count)
616622
{
617-
struct commit_list *cur, *previous;
623+
struct commit_list *cur, *previous, *result = list;
618624
int prn, index, i;
619625

620626
prn = get_prn(count);
@@ -626,15 +632,23 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
626632
for (i = 0; cur; cur = cur->next, i++) {
627633
if (i == index) {
628634
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;
633641
}
634642
previous = cur;
635643
}
636644

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;
638652
}
639653

640654
static struct commit_list *managed_skipped(struct commit_list *list,

t/t6030-bisect-porcelain.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exec </dev/null
99
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1010
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1111

12+
TEST_PASSES_SANITIZE_LEAK=true
1213
. ./test-lib.sh
1314

1415
add_line_into_file()

0 commit comments

Comments
 (0)