From: Brian Aker Date: Fri, 4 Mar 2011 21:53:26 +0000 (-0800) Subject: Fix for memory leak when parsing servers. X-Git-Tag: 0.51~27 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b5c61c39efbf6054d45507283ba74007d0e1ea61;p=awesomized%2Flibmemcached Fix for memory leak when parsing servers. --- diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index ec12c92f..9723f8b6 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -337,7 +337,9 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv if ((ptr->flags.use_udp && list[x].type != MEMCACHED_CONNECTION_UDP) || ((list[x].type == MEMCACHED_CONNECTION_UDP) && ! (ptr->flags.use_udp)) ) + { return MEMCACHED_INVALID_HOST_PROTOCOL; + } WATCHPOINT_ASSERT(list[x].hostname[0] != 0); diff --git a/libmemcached/server.c b/libmemcached/server.c index 22bd6f54..97b0b27c 100644 --- a/libmemcached/server.c +++ b/libmemcached/server.c @@ -115,7 +115,14 @@ void memcached_server_free(memcached_server_st *self) if (memcached_is_allocated(self)) { - libmemcached_free(self->root, self); + if (self->root) + { + libmemcached_free(self->root, self); + } + else + { + free(self); + } } else { diff --git a/libmemcached/server_list.c b/libmemcached/server_list.c index c20f8dbf..64b8b0c4 100644 --- a/libmemcached/server_list.c +++ b/libmemcached/server_list.c @@ -42,9 +42,12 @@ memcached_server_list_append_with_weight(memcached_server_list_st ptr, return NULL; } - /* TODO: Check return type */ + /* @todo Check return type */ memcached_server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, MEMCACHED_CONNECTION_TCP); + // Handset allocated since + new_host_list->options.is_allocated= true; + /* Backwards compatibility hack */ memcached_servers_set_count(new_host_list, count); diff --git a/tests/mem_functions.c b/tests/mem_functions.c index b5bd0880..871256cf 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -6122,6 +6122,16 @@ static test_return_t regression_bug_583031(memcached_st *unused) return TEST_SUCCESS; } +// Look for memory leak +static test_return_t regression_bug_728286(memcached_st *unused) +{ + (void)unused; + memcached_server_st *servers = memcached_servers_parse("1.2.3.4:99"); + memcached_server_free(servers); + + return TEST_SUCCESS; +} + static void memcached_die(memcached_st* mc, memcached_return error, const char* what, uint32_t it) { fprintf(stderr, "Iteration #%u: ", it); @@ -6439,6 +6449,7 @@ test_st regression_tests[]= { {"lp:490486", 1, (test_callback_fn)regression_bug_490486 }, {"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 }, {0, 0, (test_callback_fn)0} };