[PATCH] gethostid (Linux variant): Switch to struct scratch_buffer [BZ #18023]

Florian Weimer fweimer@redhat.com
Tue Jun 26 17:33:00 GMT 2018


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gethostid.patch
Type: text/x-patch
Size: 2963 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20180626/dacd2302/attachment.bin>


More information about the Libc-alpha mailing list