From a468641b355470d81f358daf274b5853093cf99d Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 8 Mar 2011 15:17:05 -0800 Subject: [PATCH] Merge in solution for lp:581030. --- libmemcached/stats.c | 21 ++++++++++++++++++--- tests/mem_functions.c | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/libmemcached/stats.c b/libmemcached/stats.c index 93012a8d..ebbc63ab 100644 --- a/libmemcached/stats.c +++ b/libmemcached/stats.c @@ -405,9 +405,20 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur memcached_return_t rc; memcached_stat_st *stats; + if (! ptr) + { + WATCHPOINT_ASSERT(memc_ptr); + return NULL; + } + + WATCHPOINT_ASSERT(error); + + unlikely (ptr->flags.use_udp) { - *error= MEMCACHED_NOT_SUPPORTED; + if (error) + *error= MEMCACHED_NOT_SUPPORTED; + return NULL; } @@ -415,7 +426,9 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur if (! stats) { - *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; + if (error) + *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; + return NULL; } @@ -445,7 +458,9 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur rc= MEMCACHED_SOME_ERRORS; } - *error= rc; + if (error) + *error= rc; + return stats; } diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 36c5717e..74ab33a0 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -6133,6 +6133,20 @@ static test_return_t regression_bug_728286(memcached_st *unused) return TEST_SUCCESS; } +static test_return_t regression_bug_581030(memcached_st *unused) +{ + (void)unused; + +#ifndef DEBUG + memcached_stat_st *local_stat= memcached_stat(NULL, NULL, NULL); + test_false(local_stat); + + memcached_stat_free(NULL, NULL); +#endif + + return TEST_SUCCESS; +} + static void memcached_die(memcached_st* mc, memcached_return error, const char* what, uint32_t it) { fprintf(stderr, "Iteration #%u: ", it); @@ -6451,6 +6465,7 @@ test_st regression_tests[]= { {"lp:583031", 1, (test_callback_fn)regression_bug_583031 }, {"lp:?", 1, (test_callback_fn)regression_bug_ }, {"lp:728286", 1, (test_callback_fn)regression_bug_728286 }, + {"lp:581030", 1, (test_callback_fn)regression_bug_581030 }, {0, 0, (test_callback_fn)0} }; -- 2.30.2