From fb41a3eee237f50ecbd6e4cf521b72a1c54c1d57 Mon Sep 17 00:00:00 2001 From: Chen Fan Date: Wed, 15 Oct 2014 17:36:29 +0800 Subject: [PATCH] conf: fix an memory leak in virSocketAddrIsNumericLocalhost() Signed-off-by: Chen Fan --- src/util/virsocketaddr.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 8c9f05fa5b..5f54e6872e 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -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; } -- GitLab