diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-06-07 13:45:58 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-06-07 13:45:58 +0000 |
commit | 1d9bc936c2b1b3bd003fe3f3fdd56b6150ca3020 (patch) | |
tree | 4d7e45537ca5e605b0de053b5dfb776cca5b046f /src/common | |
parent | a92ff1c4e91c57750e76c0f8c4f98cbaf6e5d694 (diff) | |
download | tor-1d9bc936c2b1b3bd003fe3f3fdd56b6150ca3020.tar.gz tor-1d9bc936c2b1b3bd003fe3f3fdd56b6150ca3020.zip |
Adapt patch from Adam Langley: fix possible memory leak in tor_lookup_hostname
svn:r4326
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 24266987ac..8bdecfc7fb 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -526,8 +526,9 @@ int tor_lookup_hostname(const char *name, uint32_t *addr) } else { #ifdef HAVE_GETADDRINFO int err; - struct addrinfo *res, *res_p; + struct addrinfo *res=NULL, *res_p; struct addrinfo hints; + int result = -1; memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_INET; hints.ai_socktype = SOCK_STREAM; @@ -537,14 +538,13 @@ int tor_lookup_hostname(const char *name, uint32_t *addr) if (res_p->ai_family == AF_INET) { struct sockaddr_in *sin = (struct sockaddr_in *)res_p->ai_addr; memcpy(addr, &sin->sin_addr, 4); - freeaddrinfo(res); - return 0; - } else { + result = 0; + break; } } - return -1; + freeaddrinfo(res); + return result; } - return (err == EAI_AGAIN) ? 1 : -1; #else struct hostent *ent; |