From: Yin Chen Date: Tue, 12 Aug 2008 09:16:50 +0000 (+0800) Subject: fix a logic error on memcached_server_remove which will cause double free problem X-Git-Tag: _23~12 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=99b3d2acf40a4e408b13e06e2e97db9c20b72908;p=m6w6%2Flibmemcached fix a logic error on memcached_server_remove which will cause double free problem --- diff --git a/libmemcached/memcached_connect.c b/libmemcached/memcached_connect.c index d58b354f..de69e446 100644 --- a/libmemcached/memcached_connect.c +++ b/libmemcached/memcached_connect.c @@ -34,7 +34,10 @@ static memcached_return set_hostinfo(memcached_server_st *server) } if (server->address_info) + { freeaddrinfo(server->address_info); + server->address_info= NULL; + } server->address_info= ai; return MEMCACHED_SUCCESS; @@ -177,6 +180,7 @@ static memcached_return network_connect(memcached_server_st *ptr) if (ptr->server_failure_counter >= ptr->root->server_failure_limit) { memcached_server_remove(ptr); + return MEMCACHED_FAILURE; } } /* Old connection junk still is in the structure */ diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index dd137dda..34b93c6f 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -295,15 +295,14 @@ memcached_return memcached_server_remove(memcached_server_st *st_ptr) memcpy(list+index, list+x, sizeof(memcached_server_st)); index++; } - else - { - ptr->number_of_hosts--; - } } - + ptr->number_of_hosts= index; if (st_ptr->address_info) + { freeaddrinfo(st_ptr->address_info); + st_ptr->address_info= NULL; + } run_distribution(ptr); return MEMCACHED_SUCCESS;