[PATCH 3/3] bisect: fix memory leak when returning best element
- From
- Martin Ågren <martin.agren@gmail.com>
- Date
- Nov 1, 2017, 20:34 UTC
- Message-ID
- <2ef8b41ad021638acc767c59ee65e15109a34fbf.1509557518.git.martin.agren@gmail.com>
- In-Reply-To
- <4795556016c25e4a78241362547c5468877f808d.1509557518.git.martin.agren@gmail.com>
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> --- bisect.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/bisect.c b/bisect.c index fda527b89..c1aaf632a 100644 --- a/bisect.c +++ b/bisect.c @@ -400,8 +400,12 @@ struct commit_list *find_bisection(struct commit_list *list, /* 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);
-- 2.15.0.415.gac1375d7e