During some testing with flood (~30 threads), we ran into a stack
corruption error in our code. We tracked it down to the fact that we
were using a non-reentrant version of gethostbyname. This patch lets
us call the reentrant version of gethostbyname and now we haven't
been able to recreate the segfault.
The only possible optimization would be the size of the temporary
buffer (currently 256). Roy mentioned that the address array in
hostent has a maximum of 10 entries. If so, the size of the
structure plus the maximum size of the array (10 entries) may be
sufficient. If we send in a too small buffer, we should
receive ERANGE.
Any reason we shouldn't commit? -- justin
Index: network_io/unix/sa_common.c
===================================================================
RCS file: /home/cvs/apr/network_io/unix/sa_common.c,v
retrieving revision 1.34
diff -u -r1.34 sa_common.c
--- network_io/unix/sa_common.c 2001/05/02 02:54:11 1.34
+++ network_io/unix/sa_common.c 2001/07/20 02:29:30
@@ -380,6 +380,11 @@
struct hostent *hp;
apr_sockaddr_t *cursa;
int curaddr;
+#if APR_HAS_THREADS
+ char tmp[256];
+ int hosterror;
+ struct hostent hs;
+#endif
if (family == APR_UNSPEC) {
family = APR_INET; /* we don't support IPv6 here */
@@ -395,11 +400,17 @@
}
else {
#endif
+#if APR_HAS_THREADS
+ hp = gethostbyname_r(hostname, &hs, tmp, 255, &hosterror);
+#else
hp = gethostbyname(hostname);
+#endif
if (!hp) {
#ifdef WIN32
apr_get_netos_error();
+#elif APR_HAS_THREADS
+ return (hosterror + APR_OS_START_SYSERR);
#else
return (h_errno + APR_OS_START_SYSERR);
#endif