Refactor SocketAddress::getaddrinfo - avoid calling IsValid if ::getaddrinfo has...
authorOleksiy Vyalov <ovyalov@google.com>
Thu, 27 Nov 2014 00:32:54 +0000 (00:32 +0000)
committerOleksiy Vyalov <ovyalov@google.com>
Thu, 27 Nov 2014 00:32:54 +0000 (00:32 +0000)
Otherwise, IsValid crashes on assertation in GetFamilyLength.

llvm-svn: 222862

lldb/source/Host/common/SocketAddress.cpp

index a952a83..6231631 100644 (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;
 }