From 5336d5069626a9e06e224cbc1730ee96c5742108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 26 Sep 2020 10:37:29 +0200 Subject: ref-filter: plug memory leak in reach_filter() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 21bf933928 (ref-filter: allow merged and no-merged filters, 2020-09-15) added an early return to reach_filter(). Avoid leaking the memory of a then unused array by postponing its allocation until we know we need it. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- ref-filter.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ref-filter.c b/ref-filter.c index 5550a0d34c..e0b8cd3ed8 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2239,12 +2239,14 @@ static void reach_filter(struct ref_array *array, { struct rev_info revs; int i, old_nr; - struct commit **to_clear = xcalloc(sizeof(struct commit *), array->nr); + struct commit **to_clear; struct commit_list *cr; if (!check_reachable) return; + to_clear = xcalloc(sizeof(struct commit *), array->nr); + repo_init_revisions(the_repository, &revs, NULL); for (i = 0; i < array->nr; i++) { -- cgit v1.2.3