You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by dm...@apache.org on 2014/12/13 00:41:25 UTC
[4/5] mesos git commit: Renamed getaddrinfo arguments to be more
suggestive
Renamed getaddrinfo arguments to be more suggestive
Also add missing call to freeaddrinfo when the call fails
Review: https://reviews.apache.org/r/28958
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/16fc87a1
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/16fc87a1
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/16fc87a1
Branch: refs/heads/master
Commit: 16fc87a1c62434c8f6a433c2e916b78f3aa5ae15
Parents: e864025
Author: Evelina Dumitrescu <ev...@gmail.com>
Authored: Fri Dec 12 15:29:31 2014 -0800
Committer: Dominic Hamon <dh...@twitter.com>
Committed: Fri Dec 12 15:29:54 2014 -0800
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/net.hpp | 33 ++++++++++++--------
1 file changed, 20 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/16fc87a1/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp
index 2f2298c..80578e2 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp
@@ -141,17 +141,20 @@ inline Try<std::string> hostname()
}
// TODO(evelinad): Add AF_UNSPEC when we will support IPv6
- struct addrinfo ai = createAddrInfo(SOCK_STREAM, AF_INET, AI_CANONNAME);
- struct addrinfo *aip;
+ struct addrinfo hints = createAddrInfo(SOCK_STREAM, AF_INET, AI_CANONNAME);
+ struct addrinfo *result;
- int error = getaddrinfo(host, NULL, &ai, &aip);
+ int error = getaddrinfo(host, NULL, &hints, &result);
- if (error != 0 || aip == NULL) {
+ if (error != 0 || result == NULL) {
+ if (result != NULL) {
+ freeaddrinfo(result);
+ }
return Error(gai_strerror(error));
}
- std::string hostname = aip->ai_canonname;
- freeaddrinfo(aip);
+ std::string hostname = result->ai_canonname;
+ freeaddrinfo(result);
return hostname;
}
@@ -183,19 +186,23 @@ inline Try<std::string> getHostname(uint32_t ip)
// obtained.
inline Try<uint32_t> getIP(const std::string& hostname, sa_family_t family)
{
- struct addrinfo ai, *aip;
- ai = createAddrInfo(SOCK_STREAM, family, 0);
+ struct addrinfo hints, *result;
+ hints = createAddrInfo(SOCK_STREAM, family, 0);
- int error = getaddrinfo(hostname.c_str(), NULL, &ai, &aip);
- if (error != 0 || aip == NULL) {
+ int error = getaddrinfo(hostname.c_str(), NULL, &hints, &result);
+ if (error != 0 || result == NULL) {
+ if (result != NULL ) {
+ freeaddrinfo(result);
+ }
return Error(gai_strerror(error));
}
- if (aip->ai_addr == NULL) {
+ if (result->ai_addr == NULL) {
+ freeaddrinfo(result);
return Error("Got no addresses for '" + hostname + "'");
}
- uint32_t ip = ((struct sockaddr_in*)(aip->ai_addr))->sin_addr.s_addr;
- freeaddrinfo(aip);
+ uint32_t ip = ((struct sockaddr_in*)(result->ai_addr))->sin_addr.s_addr;
+ freeaddrinfo(result);
return ip;
}