Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea5942b

Browse files
committed
Bail out early when no memory is available.
1 parent 700f0af commit ea5942b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/posix.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ int p_getaddrinfo(
6262
ai = ainfo;
6363

6464
for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
65-
ai->ai_next = malloc(sizeof(struct addrinfo));
65+
if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) {
66+
p_freeaddrinfo(ainfo);
67+
return -1;
68+
}
6669
memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo));
6770
memcpy(&ai->ai_next->ai_addr_in.sin_addr,
6871
ainfo->ai_hostent->h_addr_list[p],

0 commit comments

Comments
 (0)