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 <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin Ågren committed
Nov 5, 2017 at 21:24 UTC
f4e45cb3eb6fad4570ff63eecb37bae8102992fc
1 file changed
+5
-1
bisect.c
+5
-1
@@ -399,8 +399,12 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
399
/* Do the real work of finding bisection commit. */
400
best = do_find_bisection(list, nr, weights, find_all);
401
if (best) {
402
- if (!find_all)
402
+ if (!find_all) {
403
+ list->item = best->item;
404
+ free_commit_list(list->next);
405
+ best = list;
406
best->next = NULL;
407
+ }
408
*reaches = weight(best);
409
}
410
free(weights);