{"thread":{"id":"54308","subject":"[PATCH] ref-filter: plug memory leak in reach_filter()","startedAt":"2020-09-26T08:39:37Z","lastAt":"2020-09-26T22:40:18Z","messageCount":3,"participants":["René Scharfe","Aaron Lipman","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"406414","messageId":"d9922bbe-4e34-45fe-66a5-d7b5bf42117a@web.de","threadId":"54308","inReplyTo":null,"subject":"[PATCH] ref-filter: plug memory leak in reach_filter()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2020-09-26T08:37:29Z","receivedAt":"2020-09-26T08:39:37Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"21bf933928 (ref-filter: allow merged and no-merged filters, 2020-09-15)\nadded an early return to reach_filter().  Avoid leaking the memory of a\nthen unused array by postponing its allocation until we know we need it.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n ref-filter.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 5550a0d34c..e0b8cd3ed8 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -2239,12 +2239,14 @@ static void reach_filter(struct ref_array *array,\n {\n \tstruct rev_info revs;\n \tint i, old_nr;\n-\tstruct commit **to_clear = xcalloc(sizeof(struct commit *), array->nr);\n+\tstruct commit **to_clear;\n \tstruct commit_list *cr;\n\n \tif (!check_reachable)\n \t\treturn;\n\n+\tto_clear = xcalloc(sizeof(struct commit *), array->nr);\n+\n \trepo_init_revisions(the_repository, &revs, NULL);\n\n \tfor (i = 0; i < array->nr; i++) {\n--\n2.28.0\n"},{"id":"406427","messageId":"CAEJZ43hYgdCWGOaMHc=V_YBz0S3LCnSP6tZ1=ZTEwiNBwbHFqw@mail.gmail.com","threadId":"54308","inReplyTo":"d9922bbe-4e34-45fe-66a5-d7b5bf42117a@web.de","subject":"Re: [PATCH] ref-filter: plug memory leak in reach_filter()","fromName":"Aaron Lipman","fromEmail":"alipman88@gmail.com","sentAt":"2020-09-26T14:53:09Z","receivedAt":"2020-09-26T14:53:22Z","isPatch":true,"sender":{"key":"alipman88@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3922511?v=4"},"body":"Thanks for catching that!\n"},{"id":"406461","messageId":"xmqqft74i2lx.fsf@gitster.c.googlers.com","threadId":"54308","inReplyTo":"CAEJZ43hYgdCWGOaMHc=V_YBz0S3LCnSP6tZ1=ZTEwiNBwbHFqw@mail.gmail.com","subject":"Re: [PATCH] ref-filter: plug memory leak in reach_filter()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-09-26T22:40:10Z","receivedAt":"2020-09-26T22:40:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aaron Lipman <alipman88@gmail.com> writes:\n\n> Thanks for catching that!\n\nYeah, looks good.  Thanks, both.\n"}]}