Commit 01cda138 authored by Ian Craggs's avatar Ian Craggs

Merge pull request #123 from guilhermeferreira/fix-mem-leak

Fix memory leak on Socket_new()
parents 6e18c3bb af53c72a
...@@ -614,29 +614,28 @@ int Socket_new(char* addr, int port, int* sock) ...@@ -614,29 +614,28 @@ int Socket_new(char* addr, int port, int* sock)
{ {
if (res->ai_family == AF_INET) if (res->ai_family == AF_INET)
{ {
result = res;
break; break;
} }
res = res->ai_next; res = res->ai_next;
} }
if (result == NULL) if (res == NULL)
rc = -1; rc = -1;
else else
#if defined(AF_INET6) #if defined(AF_INET6)
if (result->ai_family == AF_INET6) if (res->ai_family == AF_INET6)
{ {
address6.sin6_port = htons(port); address6.sin6_port = htons(port);
address6.sin6_family = family = AF_INET6; address6.sin6_family = family = AF_INET6;
address6.sin6_addr = ((struct sockaddr_in6*)(result->ai_addr))->sin6_addr; address6.sin6_addr = ((struct sockaddr_in6*)(res->ai_addr))->sin6_addr;
} }
else else
#endif #endif
if (result->ai_family == AF_INET) if (res->ai_family == AF_INET)
{ {
address.sin_port = htons(port); address.sin_port = htons(port);
address.sin_family = family = AF_INET; address.sin_family = family = AF_INET;
address.sin_addr = ((struct sockaddr_in*)(result->ai_addr))->sin_addr; address.sin_addr = ((struct sockaddr_in*)(res->ai_addr))->sin_addr;
} }
else else
rc = -1; rc = -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment