This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] gethostid (Linux variant): Switch to struct scratch_buffer [BZ #18023]
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.