From: Brian Aker Date: Sun, 13 May 2012 07:17:22 +0000 (-0400) Subject: Fix for valgrind issue around memcached_result_st not being free() X-Git-Tag: 1.0.8~4^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=5e18f5bdda1bebc6e6eef25a37d0a04a30e847af;p=awesomized%2Flibmemcached Fix for valgrind issue around memcached_result_st not being free() --- diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index b03b60d8..ecce3299 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -183,9 +183,9 @@ Application::error_t Application::run(const char *args[]) posix_spawn_file_actions_t file_actions; posix_spawn_file_actions_init(&file_actions); - stdin_fd.dup_for_spawn(Application::Pipe::READ, file_actions); - stdout_fd.dup_for_spawn(Application::Pipe::WRITE, file_actions); - stderr_fd.dup_for_spawn(Application::Pipe::WRITE, file_actions); + stdin_fd.dup_for_spawn(file_actions); + stdout_fd.dup_for_spawn(file_actions); + stderr_fd.dup_for_spawn(file_actions); posix_spawnattr_t spawnattr; posix_spawnattr_init(&spawnattr); @@ -593,13 +593,20 @@ void Application::Pipe::cloexec() Application::Pipe::~Pipe() { - close(READ); - close(WRITE); + if (_pipe_fd[0] != -1) + { + ::close(_pipe_fd[0]); + } + + if (_pipe_fd[1] != -1) + { + ::close(_pipe_fd[1]); + } } -void Application::Pipe::dup_for_spawn(const close_t& arg, posix_spawn_file_actions_t& file_actions) +void Application::Pipe::dup_for_spawn(posix_spawn_file_actions_t& file_actions) { - int type= int(arg); + int type= STDIN_FILENO == _std_fd ? 0 : 1; int ret; if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _pipe_fd[type], _std_fd )) < 0) diff --git a/libtest/cmdline.h b/libtest/cmdline.h index ad1d6125..700647d3 100644 --- a/libtest/cmdline.h +++ b/libtest/cmdline.h @@ -66,8 +66,7 @@ public: void reset(); void close(const close_t& arg); - void dup_for_spawn(const close_t& arg, - posix_spawn_file_actions_t& file_actions); + void dup_for_spawn(posix_spawn_file_actions_t& file_actions); void nonblock(); void cloexec(); diff --git a/libtest/comparison.hpp b/libtest/comparison.hpp index 2a00284f..63bd08a2 100644 --- a/libtest/comparison.hpp +++ b/libtest/comparison.hpp @@ -86,6 +86,29 @@ bool _compare(const char *file, int line, const char *func, const T1_comparable& return true; } +template +bool _compare_strcmp(const char *file, int line, const char *func, const T1_comparable& __expected, const T2_comparable& __actual) +{ + if (__expected == NULL) + { + fatal_message("Expected value was NULL, programmer error"); + } + + if (__actual == NULL) + { + libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " but got NULL"; + return false; + } + + if (strncmp(__expected, __actual, strlen(__expected))) + { + libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " passed \"" << __actual << "\""; + return false; + } + + return true; +} + template bool _compare_zero(const char *file, int line, const char *func, T_comparable __actual) { diff --git a/libtest/test.h b/libtest/test.h index b5f7e47d..117e59ce 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -230,16 +230,10 @@ do \ } while (0) -#define test_strcmp(A,B) \ +#define test_strcmp(__expected, __actual) \ do \ { \ - if ((A) == NULL or (B) == NULL or strcmp((A), (B))) \ - { \ - if ((B) == NULL) fprintf(stderr, "\n%s:%d: Expected %s, got \n", __FILE__, __LINE__, (A)); \ - else fprintf(stderr, "\n%s:%d: Expected %s, got \"%s\"\n", __FILE__, __LINE__, (A), (B)); \ - libtest::create_core(); \ - return TEST_FAILURE; \ - } \ + void(libtest::_compare_strcmp(__FILE__, __LINE__, __func__, (__expected), (__actual))); \ } while (0) #define test_memcmp(A,B,C) \ diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 2f1dff72..f8ac3da6 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -4606,7 +4606,7 @@ test_return_t regression_994772_TEST(memcached_st* memc) memcached_mget(memc, keys, key_length, 1)); memcached_return_t rc; - memcached_result_st *results = memcached_fetch_result(memc, NULL, &rc); + memcached_result_st *results= memcached_fetch_result(memc, NULL, &rc); test_true(results); test_compare(MEMCACHED_SUCCESS, rc); @@ -4614,6 +4614,8 @@ test_return_t regression_994772_TEST(memcached_st* memc) uint64_t cas_value= memcached_result_cas(results); test_true(cas_value); + memcached_result_free(results); + // Bad cas value, sanity check test_true(cas_value != 9999); test_compare(MEMCACHED_END,