Commit ea5942b4cfb56eeb7375e3af2ec76545f551b4df

Sebastian Bauer 2015-12-31T11:12:57

Bail out early when no memory is available.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/src/posix.c b/src/posix.c
index 8d86aa8..de9181a 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -62,7 +62,10 @@ int p_getaddrinfo(
 	ai = ainfo;
 
 	for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
-		ai->ai_next = malloc(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],