Fix issue with checking on hosts when building new list.
[m6w6/libmemcached] / libmemcached / hosts.c
index d95dbcfff2fb0f55333afa58f368e01ecd33854d..7e68766749e39fa0e1a2b5f97cd8bc37aee4d0d1 100644 (file)
@@ -339,10 +339,15 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv
     WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
 
     instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr));
+    WATCHPOINT_ASSERT(instance);
 
     /* TODO check return type */
-    (void)memcached_server_create_with(ptr, instance, list[x].hostname,
-                                       list[x].port, list[x].weight, list[x].type);
+    instance= memcached_server_create_with(ptr, instance, list[x].hostname,
+                                           list[x].port, list[x].weight, list[x].type);
+    if (! instance)
+    {
+      return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, NULL);
+    }
     ptr->number_of_hosts++;
   }
 
@@ -444,20 +449,3 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname,
 
   return run_distribution(ptr);
 }
-
-memcached_return_t memcached_server_add_parsed(memcached_st *ptr,
-                                               const char *hostname,
-                                               size_t hostname_length,
-                                               in_port_t port,
-                                               uint32_t weight)
-{
-  char buffer[NI_MAXHOST];
-
-  memcpy(buffer, hostname, hostname_length);
-  buffer[hostname_length]= 0;
-
-  return server_add(ptr, buffer,
-                    port,
-                    weight,
-                    MEMCACHED_CONNECTION_TCP);
-}