From: Brian Aker Date: Mon, 18 Jan 2010 23:29:11 +0000 (-0800) Subject: Fix for issue where stats may not be initialized. X-Git-Tag: 0.40~87 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=c7f0791996a3814f4de76ba933890264a63feb99;p=m6w6%2Flibmemcached Fix for issue where stats may not be initialized. --- 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);