+ self->state= global_copy.state;
+ self->flags= global_copy.flags;
+ self->virtual_bucket= NULL;
+
+ self->distribution= MEMCACHED_DISTRIBUTION_MODULA;
+
+ hashkit_st *hash_ptr;
+ hash_ptr= hashkit_create(&self->hashkit);
+ if (! hash_ptr)
+ return false;
+
+ self->ketama.continuum= NULL;
+ self->ketama.continuum_count= 0;
+ self->ketama.continuum_points_counter= 0;
+ self->ketama.next_distribution_rebuild= 0;
+ self->ketama.weighted= false;
+
+ self->number_of_hosts= 0;
+ self->servers= NULL;
+ self->last_disconnected_server= NULL;
+
+ self->snd_timeout= 0;
+ self->rcv_timeout= 0;
+ self->server_failure_limit= 0;
+ self->query_id= 0;
+
+ /* TODO, Document why we picked these defaults */
+ self->io_msg_watermark= 500;
+ self->io_bytes_watermark= 65 * 1024;
+
+ self->tcp_keepidle= 0;
+
+ self->io_key_prefetch= 0;
+ self->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT;
+ self->connect_timeout= MEMCACHED_DEFAULT_CONNECT_TIMEOUT;
+ self->retry_timeout= 0;
+
+ self->send_size= -1;
+ self->recv_size= -1;
+
+ self->user_data= NULL;
+ self->number_of_replicas= 0;
+ hash_ptr= hashkit_create(&self->distribution_hashkit);
+ if (! hash_ptr)
+ return false;
+
+ self->allocators= memcached_allocators_return_default();
+
+ self->on_clone= NULL;
+ self->on_cleanup= NULL;
+ self->get_key_failure= NULL;
+ self->delete_trigger= NULL;
+ self->callbacks= NULL;
+ self->sasl.callbacks= NULL;
+ self->sasl.is_allocated= false;
+
+ self->error_messages= NULL;
+ self->prefix_key= NULL;
+ self->configure.filename= NULL;
+
+ return true;
+}
+
+static void _free(memcached_st *ptr, bool release_st)
+{
+ /* If we have anything open, lets close it now */
+ send_quit(ptr);
+ memcached_server_list_free(memcached_server_list(ptr));
+ memcached_result_free(&ptr->result);
+
+ memcached_virtual_bucket_free(ptr);
+
+ if (ptr->last_disconnected_server)
+ memcached_server_free(ptr->last_disconnected_server);
+
+ if (ptr->on_cleanup)
+ ptr->on_cleanup(ptr);
+
+ if (ptr->ketama.continuum)
+ libmemcached_free(ptr, ptr->ketama.continuum);