Index: net.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/net.cc,v retrieving revision 1.249 diff -u -p -r1.249 net.cc --- net.cc 3 Mar 2009 11:44:17 -0000 1.249 +++ net.cc 6 Mar 2009 14:28:46 -0000 @@ -264,6 +264,25 @@ struct pservent static const char *entnames[] = {"host", "proto", "serv"}; +static unionent * +realloc_ent (unionent *&dst, int sz) +{ + /* Allocate the storage needed. Allocate a rounded size to attempt to force + reuse of this buffer so that a poorly-written caller will not be using + a freed buffer. */ + unsigned rsz = 256 * ((sz + 255) / 256); + unionent * ptr; + if ((ptr = (unionent *) realloc (dst, rsz))) + dst = ptr; + return ptr; +} + +static inline hostent * +realloc_ent (int sz, hostent * ) +{ + return (hostent *) realloc_ent (_my_tls.locals.hostent_buf, sz); +} + /* Generic "dup a {host,proto,serv}ent structure" function. This is complicated because we need to be able to free the structure at any point and we can't rely on the pointer contents @@ -355,13 +374,8 @@ dup_ent (unionent *&dst, unionent *src, } } - /* Allocate the storage needed. Allocate a rounded size to attempt to force - reuse of this buffer so that a poorly-written caller will not be using - a freed buffer. */ - unsigned rsz = 256 * ((sz + 255) / 256); - dst = (unionent *) realloc (dst, rsz); - - if (dst) + /* Allocate the storage needed. */ + if (realloc_ent (dst, sz)) { memset (dst, 0, sz); /* This field is common to all *ent structures but named differently