Commit dbee683553ef4c43273b24ebc503d424c46c01f1

Edward Thomson 2016-02-28T20:13:24

Merge pull request #3567 from sba1/few-p_getaddrinfo-fixes Few p_getaddrinfo fixes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/src/posix.c b/src/posix.c
index 8d86aa8..c7201ba 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -62,8 +62,11 @@ int p_getaddrinfo(
 	ai = ainfo;
 
 	for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
-		ai->ai_next = malloc(sizeof(struct addrinfo));
-		memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo));
+		if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) {
+			p_freeaddrinfo(ainfo);
+			return -1;
+		}
+		memcpy(ai->ai_next, ainfo, sizeof(struct addrinfo));
 		memcpy(&ai->ai_next->ai_addr_in.sin_addr,
 			ainfo->ai_hostent->h_addr_list[p],
 			ainfo->ai_hostent->h_length);