Fix for valgrind issue around memcached_result_st not being free()
authorBrian Aker <brian@tangent.org>
Sun, 13 May 2012 07:17:22 +0000 (03:17 -0400)
committerBrian Aker <brian@tangent.org>
Sun, 13 May 2012 07:17:22 +0000 (03:17 -0400)
libtest/cmdline.cc
libtest/cmdline.h
libtest/comparison.hpp
libtest/test.h
tests/libmemcached-1.0/mem_functions.cc

index b03b60d861c8c56f26acb266724eb17bc0a7cba3..ecce32991e5514118e6b441728e75030224981c7 100644 (file)
@@ -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)
index ad1d61250665ba40d6aca4ceab1e2d4ec99f3db7..700647d32aff200afc01cbfa629951a060832d84 100644 (file)
@@ -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();
index 2a00284fbddef1a881feaf475c013d02ae72ecc6..63bd08a2118eb5c8485e3a8fef5c6ab4ec2edc09 100644 (file)
@@ -86,6 +86,29 @@ bool _compare(const char *file, int line, const char *func, const T1_comparable&
   return true;
 }
 
+template <class T1_comparable, class T2_comparable>
+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 <class T_comparable>
 bool _compare_zero(const char *file, int line, const char *func, T_comparable __actual)
 {
index b5f7e47d3cad9ddd7c37d68d3c51ac3778457a29..117e59ceaca767965fa88bb602116d92c366d24d 100644 (file)
@@ -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 <null>\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) \
index 2f1dff722e0cc0a5f157b56908d66aa511e42a81..f8ac3da67ce8a15482bd91dfa13115ff913c9cb1 100644 (file)
@@ -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,