Re: [PATCH v6 3/8] regex.3: Desoupify regfree() description

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/21/23 02:27, наб wrote:
> On Fri, Apr 21, 2023 at 01:35:43AM +0200, Alejandro Colomar wrote:
>> On 4/20/23 21:37, наб wrote:
>>> diff --git a/man3/regex.3 b/man3/regex.3
>>> index 3f1529583..e3dd72a74 100644
>>> --- a/man3/regex.3
>>> +++ b/man3/regex.3
>>> @@ -225,12 +225,10 @@ .SS Error reporting
>>>  .IR errbuf ;
>>>  the error string is always null-terminated, and truncated to fit.
>>>  .SS Freeing
>>> -Supplying
>>>  .BR regfree ()
>>> -with a precompiled pattern buffer,
>>> -.IR preg ,
>>> -will free the memory allocated to the pattern buffer by the compiling
>>> -process,
>>> +invalidates the pattern buffer at
>> While this ("invalidates") is true, it omits the most important information:
>> it frees the object.
> It doesn't.

You're right.  It frees memory within the object.  :/

> 
>> I think it's better to say that it frees (or
>> deallocates) the object and any memory allocated within it, since that
>> already implies invalidating it (due to
>> <https://port70.net/~nsz/c/c11/n1570.html#6.2.4p2> and
>> <https://port70.net/~nsz/c/c11/n1570.html#7.22.3p1>),
> For the precise reasons listed here:
> the regex_t object continues to exist.
> regcomp() doesn't allocate *preg, and regfree() doesn't deallocate it.
> 
>> and also tells why
>> it's necessary to call this function.  Otherwise, it's not clear why we
>> should call it.  Why would I want to invalidate a buffer?
> Admittedly, it does also "free any memory allocated by regcomp( )
> associated with preg." (Issue 8 Draft 2.1), yeah.

Yep.

> Maybe it's my neurosis that I consider "may no longer be passed to
> regexec()" the primary effect here.

:)

I wish GCC had an attribute for ensuring that in the -fanalyzer.
But [[gnu::malloc()]] only works for returned pointers, and not for
pointers initialized via a parameter, nor for returned integers.

> 
> Updated to
>   regfree() invalidates the pattern buffer at *preg, freeing any
>   associated memory; *preg must have been initialized via regcomp().

How about deinitializes?  Since regcomp(3) "initializes" the pattern
buffer, it makes sense to use complementary wording.

Cheers,
Alex

> 
> Best,

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux