[pve-devel] [PATCH 2/2] use freeaddrinfo on getaddrinfo results when done

Wolfgang Bumiller w.bumiller at proxmox.com
Fri May 8 11:39:25 CEST 2015


---
 data/src/pmxcfs.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/data/src/pmxcfs.c b/data/src/pmxcfs.c
index be90618..684bc51 100644
--- a/data/src/pmxcfs.c
+++ b/data/src/pmxcfs.c
@@ -693,6 +693,7 @@ lookup_node_ip(const char *nodename)
 	char buf[INET6_ADDRSTRLEN];
 	struct addrinfo *ainfo;
 	struct addrinfo ahints;
+	char *res = NULL;
 	memset(&ahints, 0, sizeof(ahints));
 
 	if (getaddrinfo(nodename, NULL, &ahints, &ainfo))
@@ -702,19 +703,20 @@ lookup_node_ip(const char *nodename)
 		struct sockaddr_in *sa = (struct sockaddr_in *)ainfo->ai_addr;
 		inet_ntop(ainfo->ai_family, &sa->sin_addr, buf, sizeof(buf));
 		if (strncmp(buf, "127.", 4) != 0) {
-			return g_strdup(buf);
+			res = g_strdup(buf);
 		}
 	}
-
-	if (ainfo->ai_family == AF_INET6) {
+	else if (ainfo->ai_family == AF_INET6) {
 		struct sockaddr_in6 *sa = (struct sockaddr_in6 *)ainfo->ai_addr;
 		inet_ntop(ainfo->ai_family, &sa->sin6_addr, buf, sizeof(buf));
 		if (strcmp(buf, "::1") != 0) {
-			return g_strdup(buf);
+			res = g_strdup(buf);
 		}
 	}
 
-	return NULL;
+	freeaddrinfo(ainfo);
+
+	return res;
 }
 
 static const char* 
-- 
2.1.4





More information about the pve-devel mailing list