ref-filter: plug memory leak in reach_filter()
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>
René Scharfe committed
Sep 26, 2020 at 10:37 UTC
5336d5069626a9e06e224cbc1730ee96c5742108
1 file changed
+3
-1
ref-filter.c
+3
-1
@@ -2239,12 +2239,14 @@ static void reach_filter(struct ref_array *array,
2239
{
2240
struct rev_info revs;
2241
int i, old_nr;
2242
- struct commit **to_clear = xcalloc(sizeof(struct commit *), array->nr);
2242
+ struct commit **to_clear;
2243
struct commit_list *cr;
2244
2245
if (!check_reachable)
2246
return;
2247
2248
+ to_clear = xcalloc(sizeof(struct commit *), array->nr);
2249
+
2250
repo_init_revisions(the_repository, &revs, NULL);
2251
2252
for (i = 0; i < array->nr; i++) {