From: Nick Mathewson Date: Thu, 17 Apr 2008 15:50:28 +0000 (+0000) Subject: r15214@tombo: nickm | 2008-04-17 11:47:10 -0400 X-Git-Tag: release-2.0.1-alpha~379 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc41ffde4d21a61a070c88ae57e1e18f3055b08b;p=libevent r15214@tombo: nickm | 2008-04-17 11:47:10 -0400 Make name_from_addr() threadsafe in http.c svn:r713 --- diff --git a/ChangeLog b/ChangeLog index de3ad264..eb32130c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -65,7 +65,7 @@ Changes in current version: o Correct the documentation on buffer printf functions. o Don't warn on unimplemented epoll_create(): this isn't a problem, just a reason to fall back to poll or select. o Correctly handle timeouts larger than 35 minutes on Linux with epoll.c. This is probably a kernel defect, but we'll have to support old kernels anyway even if it gets fixed. - + o Make name_from_addr() threadsafe in http.c Changes in 1.4.0: o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. diff --git a/http.c b/http.c index 338e6cfd..48d43201 100644 --- a/http.c +++ b/http.c @@ -2272,14 +2272,17 @@ evhttp_get_request_connection( evutil_socket_t fd, struct sockaddr *sa, socklen_t salen) { struct evhttp_connection *evcon; - char *hostname, *portname; + char *hostname = NULL, *portname = NULL; name_from_addr(sa, salen, &hostname, &portname); event_debug(("%s: new request from %s:%s on %d\n", __func__, hostname, portname, fd)); /* we need a connection object to put the http request on */ - if ((evcon = evhttp_connection_new(hostname, atoi(portname))) == NULL) + evcon = evhttp_connection_new(hostname, atoi(portname)); + event_free(hostname); + event_free(portname); + if (evcon == NULL) return (NULL); /* associate the base if we have one*/ @@ -2379,9 +2382,8 @@ name_from_addr(struct sockaddr *sa, socklen_t salen, char **phost, char **pport) { #ifdef HAVE_GETNAMEINFO - /* XXXX not threadsafe. */ - static char ntop[NI_MAXHOST]; - static char strport[NI_MAXSERV]; + char ntop[NI_MAXHOST]; + char strport[NI_MAXSERV]; int ni_result; if ((ni_result = getnameinfo(sa, salen, @@ -2391,10 +2393,11 @@ name_from_addr(struct sockaddr *sa, socklen_t salen, event_err(1, "getnameinfo failed"); else event_errx(1, "getnameinfo failed: %s", gai_strerror(ni_result)); + return; } - - *phost = ntop; - *pport = strport; + + *phost = event_strdup(ntop); + *pport = event_strdup(strport); #else /* XXXX */ #endif