conf: fix an memory leak in virSocketAddrIsNumericLocalhost()

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
This commit is contained in:
Chen Fan 2014-10-15 17:36:29 +08:00 committed by Ján Tomko
parent 3b9a26a325
commit fb41a3eee2

View File

@ -894,19 +894,24 @@ virSocketAddrIsNumericLocalhost(const char *addr)
struct in_addr tmp = { .s_addr = htonl(INADDR_LOOPBACK) };
struct sockaddr_in *inet4;
struct sockaddr_in6 *inet6;
bool ret = false;
if (virSocketAddrParseInternal(&res, addr, AF_UNSPEC, false) < 0)
return false;
return ret;
switch (res->ai_addr->sa_family) {
case AF_INET:
inet4 = (struct sockaddr_in*) res->ai_addr;
return memcmp(&inet4->sin_addr.s_addr, &tmp.s_addr,
sizeof(inet4->sin_addr.s_addr)) == 0;
ret = memcmp(&inet4->sin_addr.s_addr, &tmp.s_addr,
sizeof(inet4->sin_addr.s_addr)) == 0;
break;
case AF_INET6:
inet6 = (struct sockaddr_in6*) res->ai_addr;
return IN6_IS_ADDR_LOOPBACK(&(inet6->sin6_addr));
ret = IN6_IS_ADDR_LOOPBACK(&(inet6->sin6_addr));
break;
}
return false;
freeaddrinfo(res);
return ret;
}