From c7f0791996a3814f4de76ba933890264a63feb99 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 18 Jan 2010 15:29:11 -0800 Subject: [PATCH] Fix for issue where stats may not be initialized. --- libmemcached/stats.c | 25 +++++++++++++------------ tests/mem_functions.c | 3 +-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libmemcached/stats.c b/libmemcached/stats.c index d162277a..a47b2820 100644 --- a/libmemcached/stats.c +++ b/libmemcached/stats.c @@ -357,7 +357,6 @@ error: memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return_t *error) { - uint32_t x; memcached_return_t rc; memcached_stat_st *stats; @@ -369,29 +368,32 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur stats= libmemcached_calloc(ptr, memcached_server_count(ptr), sizeof(memcached_stat_st)); - stats->root= ptr; - - if (!stats) + if (! stats) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; } rc= MEMCACHED_SUCCESS; - for (x= 0; x < memcached_server_count(ptr); x++) + for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { memcached_return_t temp_return; memcached_server_instance_st *instance; + memcached_stat_st *stat_instance; + + stat_instance= stats + x; + + stat_instance->root= ptr; instance= memcached_server_instance_fetch(ptr, x); if (ptr->flags.binary_protocol) { - temp_return= binary_stats_fetch(stats + x, args, instance); + temp_return= binary_stats_fetch(stat_instance, args, instance); } else { - temp_return= ascii_stats_fetch(stats + x, args, instance); + temp_return= ascii_stats_fetch(stat_instance, args, instance); } if (temp_return != MEMCACHED_SUCCESS) @@ -442,11 +444,10 @@ char ** memcached_stat_get_keys(memcached_st *ptr, char **list; size_t length= sizeof(memcached_stat_keys); - (void)memc_stat; -#if 0 - list= libmemcached_malloc(memc_stat ? memc_stat->root : ptr, length); -#endif - list= libmemcached_malloc(ptr, length); + list= libmemcached_malloc(memc_stat && memc_stat->root + ? memc_stat->root + : ptr, + length); if (!list) { diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 5460078c..700003f3 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -1696,7 +1696,6 @@ static test_return_t version_string_test(memcached_st *memc __attribute__((unuse static test_return_t get_stats(memcached_st *memc) { - unsigned int x; char **stat_list; char **ptr; memcached_return_t rc; @@ -1708,7 +1707,7 @@ static test_return_t get_stats(memcached_st *memc) test_true(rc == MEMCACHED_SUCCESS); test_true(memc_stat); - for (x= 0; x < memcached_server_count(memc); x++) + for (uint32_t x= 0; x < memcached_server_count(memc); x++) { stat_list= memcached_stat_get_keys(memc, memc_stat+x, &rc); test_true(rc == MEMCACHED_SUCCESS); -- 2.30.2