Skip to content

Commit 5336d50

Browse files
rscharfegitster
authored andcommitted
ref-filter: plug memory leak in reach_filter()
21bf933 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b59cdff commit 5336d50

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ref-filter.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,12 +2239,14 @@ static void reach_filter(struct ref_array *array,
22392239
{
22402240
struct rev_info revs;
22412241
int i, old_nr;
2242-
struct commit **to_clear = xcalloc(sizeof(struct commit *), array->nr);
2242+
struct commit **to_clear;
22432243
struct commit_list *cr;
22442244

22452245
if (!check_reachable)
22462246
return;
22472247

2248+
to_clear = xcalloc(sizeof(struct commit *), array->nr);
2249+
22482250
repo_init_revisions(the_repository, &revs, NULL);
22492251

22502252
for (i = 0; i < array->nr; i++) {

0 commit comments

Comments
 (0)