]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ref-filter: plug memory leak in reach_filter()
authorRené Scharfe <l.s.r@web.de>
Sat, 26 Sep 2020 08:37:29 +0000 (10:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 26 Sep 2020 22:39:49 +0000 (15:39 -0700)
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 <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ref-filter.c

index 5550a0d34c0940372a7ebe647b4a977f8a66793a..e0b8cd3ed851454308781912f98d404b790fec57 100644 (file)
@@ -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++) {