malloc in gethostbyname
bernds_cb1 at t-online.de
Tue Jun 10 11:59:54 UTC 2008
For gethostbyname and related functions, I can see two alternatives to
just reverting to pre-uc_malloc state, either of which would enable us
to reduce the amount of static buffers.
Looking at some other C libraries, glibc still seems to use static
buffers, but in the FreeBSD C library, there is a dynamic allocation:
per thread, even, from what I can tell. Of course they don't just exit
when it fails, but they return NULL from gethostbyXXX (without setting
h_errno or errno though, so it doesn't seem all that robust either).
I had the idea of adding a config option that only leaves in the _r
variants of these functions and thus eliminates the static buffers.
While investigating this, I've hit a slight obstacle and discovered a
bug: getnameinfo, which is documented as one of the replacements for
gethostbyXXX, uses gethostbyaddr internally, which of course means that
it isn't reentrant. In glibc, it uses temporary buffers on the stack
and calls gethostbyaddr_r. We could do the same; the advantage would be
that we'd have reentrancy and we could ifdef out the non-reentrant
functions, but we'd also enlarge the stack requirements which is
unfortunate for nommu users. OTOH, the other function in the pair,
getaddrinfo, already uses local buffers on the stack, so it's not
Comments? Where should we go with this?
This footer brought to you by insane German lawmakers.
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft Muenchen, Registergericht Muenchen HRB 40368
Geschaeftsfuehrer Thomas Wessel, William A. Martin, Margaret Seif
More information about the uClibc