[PATCH] gethostid (Linux variant): Switch to struct scratch_buffer [BZ #18023]
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue Jun 26 17:52:00 GMT 2018
On 26/06/2018 14:33, Florian Weimer wrote:
> On 06/26/2018 06:58 PM, Adhemerval Zanella wrote:
>>> + /* Determine the IP address of the host name. */
>>> +Â struct scratch_buffer tmpbuf;
>>> +Â scratch_buffer_init (&tmpbuf);
>>> +Â while (true)
>>> +Â Â Â {
>>> +Â Â Â Â Â int ret = __gethostbyname_r (hostname, &hostbuf,
>>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tmpbuf.data, tmpbuf.length, &hp, &herr);
>>> +Â Â Â Â Â if (ret == 0)
>>> +Â Â Â break;
>>> +Â Â Â Â Â else
>>> +Â Â Â {
>>> +     /* Enlarge the buffer on ERANGE. */
>>> +Â Â Â Â Â if (herr == NETDB_INTERNAL && errno == ERANGE)
>>> +Â Â Â Â Â Â Â {
>>> +Â Â Â Â Â Â Â Â Â if (!scratch_buffer_grow (&tmpbuf))
>>> +Â Â Â Â Â Â Â return 0;
>>> +Â Â Â Â Â Â Â }
>>> +Â Â Â Â Â else
>>> +       /* Other errors are a failure. Return an arbitrary value. */
>> Shouldn' it call 'scratch_buffer_free' here for the case the buffer is
>> grown and a subsequent __gethostbyname_r results something different
>> than ERANGE (assuming it is possible)?
>
> Thanks, you are right. New patch attached.
>
> Florian
New version LGTM, thanks.
More information about the Libc-alpha
mailing list