From db3442ca6769650638eab10b130a54882045fff0 Mon Sep 17 00:00:00 2001 From: Date: Mon, 28 Jul 2008 21:55:31 -0700 Subject: [PATCH] Fix for lingerd and bad free. --- libmemcached/common.h | 2 ++ libmemcached/memcached_connect.c | 18 +++++++++++------- libmemcached/memcached_hash.c | 1 - libmemcached/memcached_hosts.c | 3 ++- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libmemcached/common.h b/libmemcached/common.h index 0c9b87ce..d496cf77 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -113,5 +113,7 @@ memcached_return memcachd_key_test(char **keys, size_t *key_length, memcached_return run_distribution(memcached_st *ptr); +uint32_t generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm); + uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length); #endif /* __COMMON_H__ */ diff --git a/libmemcached/memcached_connect.c b/libmemcached/memcached_connect.c index 7d6f85a4..a4ed6680 100644 --- a/libmemcached/memcached_connect.c +++ b/libmemcached/memcached_connect.c @@ -48,18 +48,11 @@ static memcached_return set_socket_options(memcached_server_st *ptr) if (ptr->root->flags & MEM_NO_BLOCK) { int error; - struct linger linger; struct timeval waittime; waittime.tv_sec= 10; waittime.tv_usec= 0; - linger.l_onoff= 1; - linger.l_linger= MEMCACHED_DEFAULT_TIMEOUT; - error= setsockopt(ptr->fd, SOL_SOCKET, SO_LINGER, - &linger, (socklen_t)sizeof(struct linger)); - WATCHPOINT_ASSERT(error == 0); - error= setsockopt(ptr->fd, SOL_SOCKET, SO_SNDTIMEO, &waittime, (socklen_t)sizeof(struct timeval)); WATCHPOINT_ASSERT(error == 0); @@ -69,6 +62,17 @@ static memcached_return set_socket_options(memcached_server_st *ptr) WATCHPOINT_ASSERT(error == 0); } + { + int error; + struct linger linger; + + linger.l_onoff= 1; + linger.l_linger= MEMCACHED_DEFAULT_TIMEOUT; + error= setsockopt(ptr->fd, SOL_SOCKET, SO_LINGER, + &linger, (socklen_t)sizeof(struct linger)); + WATCHPOINT_ASSERT(error == 0); + } + if (ptr->root->flags & MEM_TCP_NODELAY) { int flag= 1; diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index 75a1537a..b8c8cfe5 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -163,7 +163,6 @@ unsigned int dispatch_host(memcached_st *ptr, uint32_t hash) uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length) { uint32_t hash= 1; /* Just here to remove compile warning */ - uint32_t result= 1; WATCHPOINT_ASSERT(ptr->number_of_hosts); diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index 55d7a49d..c52aa096 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -173,7 +173,8 @@ memcached_return update_continuum(memcached_st *ptr) qsort(ptr->continuum, ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER, sizeof(memcached_continuum_item_st), continuum_item_cmp); ptr->continuum_points_counter= pointer_counter; - memcached_stat_free(NULL, stat_p); + if (stat_p) + memcached_stat_free(NULL, stat_p); #ifdef HAVE_DEBUG for (index= 0; index < ((ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER) - 1); index++) -- 2.30.2