Skip to content

Commit f4e45cb

Browse files
Martin Ågrengitster
authored andcommitted
bisect: fix memory leak when returning best element
When `find_bisection()` returns a single list entry, it leaks the other entries. Move the to-be-returned item to the front and free the remainder. Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c11718 commit f4e45cb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bisect.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,12 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
399399
/* Do the real work of finding bisection commit. */
400400
best = do_find_bisection(list, nr, weights, find_all);
401401
if (best) {
402-
if (!find_all)
402+
if (!find_all) {
403+
list->item = best->item;
404+
free_commit_list(list->next);
405+
best = list;
403406
best->next = NULL;
407+
}
404408
*reaches = weight(best);
405409
}
406410
free(weights);

0 commit comments

Comments
 (0)