diff mbox series

ref-filter: plug memory leak in reach_filter()

Message ID d9922bbe-4e34-45fe-66a5-d7b5bf42117a@web.de (mailing list archive)
State New, archived
Headers show
Series ref-filter: plug memory leak in reach_filter() | expand

Commit Message

René Scharfe Sept. 26, 2020, 8:37 a.m. UTC
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>
---
 ref-filter.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--
2.28.0

Comments

Aaron Lipman Sept. 26, 2020, 2:53 p.m. UTC | #1
Thanks for catching that!
Junio C Hamano Sept. 26, 2020, 10:40 p.m. UTC | #2
Aaron Lipman <alipman88@gmail.com> writes:

> Thanks for catching that!

Yeah, looks good.  Thanks, both.
diff mbox series

Patch

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++) {