提交 fb41a3ee 编写于 作者: C Chen Fan 提交者: Ján Tomko

conf: fix an memory leak in virSocketAddrIsNumericLocalhost()

Signed-off-by: NChen Fan <chen.fan.fnst@cn.fujitsu.com>
上级 3b9a26a3
...@@ -894,19 +894,24 @@ virSocketAddrIsNumericLocalhost(const char *addr) ...@@ -894,19 +894,24 @@ virSocketAddrIsNumericLocalhost(const char *addr)
struct in_addr tmp = { .s_addr = htonl(INADDR_LOOPBACK) }; struct in_addr tmp = { .s_addr = htonl(INADDR_LOOPBACK) };
struct sockaddr_in *inet4; struct sockaddr_in *inet4;
struct sockaddr_in6 *inet6; struct sockaddr_in6 *inet6;
bool ret = false;
if (virSocketAddrParseInternal(&res, addr, AF_UNSPEC, false) < 0) if (virSocketAddrParseInternal(&res, addr, AF_UNSPEC, false) < 0)
return false; return ret;
switch (res->ai_addr->sa_family) { switch (res->ai_addr->sa_family) {
case AF_INET: case AF_INET:
inet4 = (struct sockaddr_in*) res->ai_addr; inet4 = (struct sockaddr_in*) res->ai_addr;
return memcmp(&inet4->sin_addr.s_addr, &tmp.s_addr, ret = memcmp(&inet4->sin_addr.s_addr, &tmp.s_addr,
sizeof(inet4->sin_addr.s_addr)) == 0; sizeof(inet4->sin_addr.s_addr)) == 0;
break;
case AF_INET6: case AF_INET6:
inet6 = (struct sockaddr_in6*) res->ai_addr; 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;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册