mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
conf: fix an memory leak in virSocketAddrIsNumericLocalhost()
Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
This commit is contained in:
parent
3b9a26a325
commit
fb41a3eee2
@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user