From 92104790f8c3330d957f43aac5cc73134482fd83 Mon Sep 17 00:00:00 2001 From: Date: Fri, 2 May 2008 06:14:18 -0700 Subject: [PATCH] More tests for consistent. Fixed memory leak around addrinfo when host constantly fails. --- ChangeLog | 2 ++ clients/memslap.c | 3 --- libmemcached/memcached_connect.c | 10 ++++--- libmemcached/memcached_hosts.c | 6 +++++ tests/function.c | 46 ++++++++++++++++++++++++++++++++ tests/server.c | 1 - 6 files changed, 60 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef18c9fb..5750968b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * New consistent distribution tests. + * Found a memory leak when a server constantly fails. * Changed default timeout to 1 second for poll timeouts * Wheel uses less memory/dynamic allocation for size (no longer limited to 512 hosts by default. diff --git a/clients/memslap.c b/clients/memslap.c index 52abb4b1..01f11e2d 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -355,9 +355,6 @@ void *run_task(void *p) if (context->execute_pairs) pairs_free(context->execute_pairs); - if (context->initial_pairs) - pairs_free(context->initial_pairs); - free(context); pthread_mutex_lock(&counter_mutex); diff --git a/libmemcached/memcached_connect.c b/libmemcached/memcached_connect.c index 74469870..7d6f85a4 100644 --- a/libmemcached/memcached_connect.c +++ b/libmemcached/memcached_connect.c @@ -218,6 +218,12 @@ test_connect: WATCHPOINT_NUMBER(ptr->root->connect_timeout); close(ptr->fd); ptr->fd= -1; + if (ptr->address_info) + { + freeaddrinfo(ptr->address_info); + ptr->address_info= NULL; + } + return MEMCACHED_ERRNO; } @@ -231,7 +237,6 @@ test_connect: default: handle_retry: ptr->cached_errno= errno; - WATCHPOINT_ERRNO(ptr->cached_errno); close(ptr->fd); ptr->fd= -1; if (ptr->root->retry_timeout) @@ -290,9 +295,6 @@ memcached_return memcached_connect(memcached_server_st *ptr) WATCHPOINT_ASSERT(0); } - if (rc != MEMCACHED_SUCCESS) - WATCHPOINT_ERROR(rc); - LIBMEMCACHED_MEMCACHED_CONNECT_END(); return rc; diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index 18e37d7b..231b2167 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -121,7 +121,10 @@ void server_list_free(memcached_st *ptr, memcached_server_st *servers) for (x= 0; x < servers->count; x++) if (servers[x].address_info) + { freeaddrinfo(servers[x].address_info); + servers[x].address_info= NULL; + } if (ptr && ptr->call_free) ptr->call_free(ptr, servers); @@ -218,7 +221,10 @@ memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *l sizeof(memcached_server_st) * (count + ptr->number_of_hosts)); if (!new_host_list) + { + assert(0); return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + } ptr->hosts= new_host_list; diff --git a/tests/function.c b/tests/function.c index cc63dadd..d3d23e47 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2175,6 +2175,42 @@ test_return generate_buffer_data(memcached_st *memc) return 0; } +test_return get_read_count(memcached_st *memc) +{ + unsigned int x; + memcached_return rc; + memcached_st *clone; + + clone= memcached_clone(NULL, memc); + assert(clone); + + memcached_server_add(clone, "localhost", 6666); + + { + char *return_value; + size_t return_value_length; + uint32_t flags; + uint32_t count; + + for (x= count= 0; x < global_count; x++) + { + return_value= memcached_get(clone, global_keys[x], global_keys_length[x], + &return_value_length, &flags, &rc); + if (rc == MEMCACHED_SUCCESS) + { + count++; + if (return_value) + free(return_value); + } + } + fprintf(stderr, "\t%u -> %u", global_count, count); + } + + memcached_free(clone); + + return 0; +} + test_return get_read(memcached_st *memc) { unsigned int x; @@ -2695,6 +2731,13 @@ test_st generate_tests[] ={ {0, 0, 0} }; +test_st consistent_tests[] ={ + {"generate_pairs", 1, generate_pairs }, + {"generate_data", 1, generate_data }, + {"get_read", 0, get_read_count }, + {"cleanup", 1, cleanup_pairs }, + {0, 0, 0} +}; collection_st collection[] ={ {"block", 0, 0, tests}, @@ -2728,6 +2771,9 @@ collection_st collection[] ={ {"generate_md5", pre_md5, 0, generate_tests}, {"generate_murmur", pre_murmur, 0, generate_tests}, {"generate_nonblock", pre_nonblock, 0, generate_tests}, + {"consistent_not", 0, 0, consistent_tests}, + {"consistent_ketama", pre_behavior_ketama, 0, consistent_tests}, + {"consistent_wheel", enable_wheel, 0, consistent_tests}, {0, 0, 0, 0} }; diff --git a/tests/server.c b/tests/server.c index f5e44a9b..1248981b 100644 --- a/tests/server.c +++ b/tests/server.c @@ -42,7 +42,6 @@ void server_startup(server_startup_st *construct) else sprintf(buffer, "memcached -d -P /tmp/%umemc.pid -t 1 -p %u", x, x+ TEST_PORT_BASE); status= system(buffer); - WATCHPOINT_ASSERT(status == 0); count= sprintf(end_ptr, "localhost:%u,", x + TEST_PORT_BASE); end_ptr+= count; } -- 2.30.2