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>
This commit is contained in:

committed by
Junio C Hamano

parent
2b7706aae5
commit
c1e98f9010
30
bisect.c
30
bisect.c
@ -442,9 +442,12 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
|
|||||||
best->next = NULL;
|
best->next = NULL;
|
||||||
}
|
}
|
||||||
*reaches = weight(best);
|
*reaches = weight(best);
|
||||||
|
} else {
|
||||||
|
free_commit_list(*commit_list);
|
||||||
}
|
}
|
||||||
free(weights);
|
|
||||||
*commit_list = best;
|
*commit_list = best;
|
||||||
|
|
||||||
|
free(weights);
|
||||||
clear_commit_weight(&commit_weight);
|
clear_commit_weight(&commit_weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,8 +560,11 @@ struct commit_list *filter_skipped(struct commit_list *list,
|
|||||||
tried = &list->next;
|
tried = &list->next;
|
||||||
} else {
|
} else {
|
||||||
if (!show_all) {
|
if (!show_all) {
|
||||||
if (!skipped_first || !*skipped_first)
|
if (!skipped_first || !*skipped_first) {
|
||||||
|
free_commit_list(next);
|
||||||
|
free_commit_list(filtered);
|
||||||
return list;
|
return list;
|
||||||
|
}
|
||||||
} else if (skipped_first && !*skipped_first) {
|
} else if (skipped_first && !*skipped_first) {
|
||||||
/* This means we know it's not skipped */
|
/* This means we know it's not skipped */
|
||||||
*skipped_first = -1;
|
*skipped_first = -1;
|
||||||
@ -614,7 +620,7 @@ static int sqrti(int val)
|
|||||||
|
|
||||||
static struct commit_list *skip_away(struct commit_list *list, int count)
|
static struct commit_list *skip_away(struct commit_list *list, int count)
|
||||||
{
|
{
|
||||||
struct commit_list *cur, *previous;
|
struct commit_list *cur, *previous, *result = list;
|
||||||
int prn, index, i;
|
int prn, index, i;
|
||||||
|
|
||||||
prn = get_prn(count);
|
prn = get_prn(count);
|
||||||
@ -626,15 +632,23 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
|
|||||||
for (i = 0; cur; cur = cur->next, i++) {
|
for (i = 0; cur; cur = cur->next, i++) {
|
||||||
if (i == index) {
|
if (i == index) {
|
||||||
if (!oideq(&cur->item->object.oid, current_bad_oid))
|
if (!oideq(&cur->item->object.oid, current_bad_oid))
|
||||||
return cur;
|
result = cur;
|
||||||
if (previous)
|
else if (previous)
|
||||||
return previous;
|
result = previous;
|
||||||
return list;
|
else
|
||||||
|
result = list;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
previous = cur;
|
previous = cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
for (cur = list; cur != result; ) {
|
||||||
|
struct commit_list *next = cur->next;
|
||||||
|
free(cur);
|
||||||
|
cur = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct commit_list *managed_skipped(struct commit_list *list,
|
static struct commit_list *managed_skipped(struct commit_list *list,
|
||||||
|
@ -9,6 +9,7 @@ exec </dev/null
|
|||||||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
||||||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
add_line_into_file()
|
add_line_into_file()
|
||||||
|
Reference in New Issue
Block a user