Re: [PATCH 12/20] http-backend.c: fix cmd_main() memory leak, refactor reg{exec,free}()
- From
René Scharfe <l.s.r@web.de>
- Date
- Dec 29, 2022, 15:49 UTC
- Message-ID
- <ca564bd3-cd45-aa4e-7c5a-8fe4e0cefbce@web.de>
- In-Reply-To
- <xmqqpmc2mzpw.fsf@gitster.g>
Am 29.12.22 um 08:32 schrieb Junio C Hamano:
Show 27 quoted lines
> René Scharfe <l.s.r@web.de> writes:
>
>>> diff --git a/http-backend.c b/http-backend.c
>>> index 6eb3b2fe51c..9bb63c458b1 100644
>>> --- a/http-backend.c
>>> +++ b/http-backend.c
>>> @@ -759,10 +759,14 @@ int cmd_main(int argc, const char **argv)
>>> struct service_cmd *c = &services[i];
>>> regex_t re;
>>> regmatch_t out[1];
>>> + int ret;
>>>
>>> if (regcomp(&re, c->pattern, REG_EXTENDED))
>>> die("Bogus regex in service table: %s", c->pattern);
>>> - if (!regexec(&re, dir, 1, out, 0)) {
>>> + ret = regexec(&re, dir, 1, out, 0);
>>> + regfree(&re);
>>> +
>>> + if (!ret) {
>>> size_t n;
>>>
>>
>> ... i.e. right here. But only after copying the offsets out of "out"!
>
> "only after..."? Do out[i].rm_eo and out[i].rm_so become invalid
> after calling regfree() on the regex out[] was taken against? I do
> not think so, and am confused by the comment.Nah, sorry, I was confused. o_O "out" is not affected by regfree(), of course; it's supplied by the regexec() caller -- cmd_main() owns it.
René