From f4e45cb3eb6fad4570ff63eecb37bae8102992fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=85gren?= Date: Sun, 5 Nov 2017 21:24:31 +0100 Subject: bisect: fix memory leak when returning best element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano diff --git a/bisect.c b/bisect.c index b194150..3756f12 100644 --- a/bisect.c +++ b/bisect.c @@ -399,8 +399,12 @@ void find_bisection(struct commit_list **commit_list, int *reaches, /* Do the real work of finding bisection commit. */ best = do_find_bisection(list, nr, weights, find_all); if (best) { - if (!find_all) + if (!find_all) { + list->item = best->item; + free_commit_list(list->next); + best = list; best->next = NULL; + } *reaches = weight(best); } free(weights); -- cgit v0.10.2-6-g49f6