{
for (x= 0; x < ptr->number_of_hosts; x++)
{
- if (ptr->hosts[x].fd > 0)
+ if (ptr->hosts[x].fd == -1)
close(ptr->hosts[x].fd);
-
- if (ptr->hosts[x].hostname)
- free(ptr->hosts[x].hostname);
+ free(ptr->hosts[x].hostname);
}
free(ptr->hosts);
hostname= "localhost";
- ptr->hosts= (memcached_host_st *)realloc(ptr->hosts, sizeof(memcached_host_st) * (size_t)ptr->number_of_hosts);
+ ptr->hosts= (memcached_host_st *)realloc(ptr->hosts, sizeof(memcached_host_st) * (ptr->number_of_hosts+1));
+ memset(ptr->hosts, 0, sizeof(memcached_host_st) * (size_t)ptr->number_of_hosts);
ptr->hosts[ptr->number_of_hosts].hostname=
- (char *)malloc(sizeof(char) * strlen(hostname));
+ (char *)malloc(sizeof(char) * (strlen(hostname) + 1));
+ memset(ptr->hosts[ptr->number_of_hosts].hostname, 0, sizeof(char) * (strlen(hostname) + 1));
memcpy(ptr->hosts[ptr->number_of_hosts].hostname, hostname, strlen(hostname));
ptr->hosts[ptr->number_of_hosts].port= port;
ptr->hosts[ptr->number_of_hosts].fd= -1;
char *string_ptr;
unsigned int server_key;
+ *value_length= 0;
*error= memcached_connect(ptr);
if (*error != MEMCACHED_SUCCESS)
memcached_deinit(memc);
}
+void connection_test(void)
+{
+ memcached_return rc;
+ memcached_st *memc;
+ memc= memcached_init(NULL);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(memc);
+ memcached_deinit(memc);
+}
+
void set_test(void)
{
memcached_st *memc;
string= memcached_get(memc, key, strlen(key),
&string_length, &flags, &rc);
+ printf("RC %u\n", rc);
+ assert(rc == MEMCACHED_NOTFOUND);
assert(string_length == 0);
assert(!string);
init_test();
allocation_test();
+ connection_test();
set_test();
add_test();
replace_test();