Refactor SocketAddress::getaddrinfo - avoid calling IsValid if ::getaddrinfo has failed.

Otherwise, IsValid crashes on assertation in GetFamilyLength.

llvm-svn: 222862
This commit is contained in:
Oleksiy Vyalov 2014-11-27 00:32:54 +00:00
parent a662d16314
commit e13d71c57c
1 changed files with 7 additions and 3 deletions

View File

@ -214,6 +214,8 @@ SocketAddress::getaddrinfo (const char *host,
int ai_protocol,
int ai_flags)
{
Clear ();
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = ai_family;
@ -221,15 +223,17 @@ SocketAddress::getaddrinfo (const char *host,
hints.ai_protocol = ai_protocol;
hints.ai_flags = ai_flags;
bool result = false;
struct addrinfo *service_info_list = NULL;
int err = ::getaddrinfo (host, service, &hints, &service_info_list);
if (err == 0 && service_info_list)
{
*this = service_info_list;
else
Clear();
result = IsValid ();
}
:: freeaddrinfo (service_info_list);
return IsValid();
return result;
}