From: Brian Aker Date: Sat, 24 Nov 2007 00:38:14 +0000 (-0800) Subject: Memory leak for failed attempt to use memcached_result_free() X-Git-Tag: _11~11 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=45485a190a09b078c83f2dcf9e3668a1198fc0c9;p=m6w6%2Flibmemcached Memory leak for failed attempt to use memcached_result_free() --- diff --git a/ChangeLog b/ChangeLog index 9829ffdf..a10bca6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.11 * Added option to memcache_behavior_set() so that poll() can be timed out. + * Fixed memory leak in case of using memcached_fetch_result() where no + value was returned. 0.10 Tue Nov 20 23:22:31 PST 2007 * Added append binary test. diff --git a/include/memcached.h b/include/memcached.h index 54f52952..bef7e5d6 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -257,11 +257,11 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, memcached_return *error); /* Server Public functions */ -#define memcached_server_count(A) A->number_of_hosts -#define memcached_server_name(A,B) B.hostname -#define memcached_server_port(A,B) B.port -#define memcached_server_list(A) A->hosts -#define memcached_server_response_count(A,B) A->hosts[B].stack_responses +#define memcached_server_count(A) (A)->number_of_hosts +#define memcached_server_name(A,B) (B).hostname +#define memcached_server_port(A,B) (B).port +#define memcached_server_list(A) (A)->hosts +#define memcached_server_response_count(A,B) (A)->hosts[B].stack_responses memcached_return memcached_server_add_udp(memcached_st *ptr, char *hostname, diff --git a/lib/memcached_get.c b/lib/memcached_get.c index 09ec8a37..38f6865b 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -380,16 +380,16 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, } else if (*error == MEMCACHED_END && memcached_string_length((memcached_string_st *)(&result->value)) == 0) { - return NULL; + goto error; } else if (*error == MEMCACHED_END) { WATCHPOINT_ASSERT(0); /* If this happens we have somehow messed up the fetch */ - return NULL; + goto error; } else if (*error != MEMCACHED_SUCCESS) { - return NULL; + goto error; } else { @@ -398,5 +398,8 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, } +error: + memcached_result_free(result); + return NULL; }