mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
To: gilles@poolp.org
Cc: musl@lists.openwall.com
Subject: Re: freeaddrinfo() comments and questions
Date: Sat, 23 Nov 2019 17:50:08 +0100	[thread overview]
Message-ID: <87lfs67d1b.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <9a9f93674d04ac477e556a307b91ac54@poolp.org> (gilles's message of "Sat, 23 Nov 2019 16:31:35 +0000")

* gilles:

> November 23, 2019 5:05 PM, "Florian Weimer" <fw@deneb.enyo.de> wrote:
>
>> * gilles:
>> 
>>> In these other implementations, it is possible to write a custom
>>> struct addrinfo allocator and use freeaddrinfo() on it, just like it
>>> is possible to use getaddrinfo() and use a custom release function on
>>> it. This is not a very common use-case, granted, but it is one
>>> nonetheless, and one that works and has worked in a portable way for a
>>> long time across a wide variety of systems.
>> 
>> I think this is clearly undefined. There is no way to know how
>> storage for ai_addr and ai_canonname is managed. These pointers could
>> point to separate allocations, made with malloc. They could be
>> interior pointers to the same top-level allocation at which start the
>> struct addrinfo object is allocated. Nothing even needs to use
>> malloc, including the outer struct addrinfo object.
>
> Fair enough for this use-case, I think you are right and it works by accident.
>
> What is your opinion on the other comments ?

The most obvious interpretation is that callers can tweak the ai_next
member before calling freeaddrinfo, and that freeaddrinfo performs the
usual iteration over this single-linked list, freeing each list
element individually.

In general, relying on this does not seem particularly useful to me.
Applications should probably call freeaddrinfo only on the pointer
provided by getaddrinfo, and refrain from writing to any struct
members.


  reply	other threads:[~2019-11-23 16:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-23 15:46 gilles
2019-11-23 16:05 ` Florian Weimer
2019-11-23 17:41   ` Rich Felker
2019-11-23 16:31 ` gilles
2019-11-23 16:50   ` Florian Weimer [this message]
2019-11-23 17:48     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lfs67d1b.fsf@mid.deneb.enyo.de \
    --to=fw@deneb.enyo.de \
    --cc=gilles@poolp.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).