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

Skip to content

Commit dbee683

Browse files
author
Edward Thomson
committed
Merge pull request libgit2#3567 from sba1/few-p_getaddrinfo-fixes
Few p_getaddrinfo fixes
2 parents 1a9d7c9 + 9f9df4b commit dbee683

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/posix.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ 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));
66-
memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo));
65+
if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) {
66+
p_freeaddrinfo(ainfo);
67+
return -1;
68+
}
69+
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],
6972
ainfo->ai_hostent->h_length);

0 commit comments

Comments
 (0)