Removing memory issue/cleanup for threads in src/memslap.c
[awesomized/libmemcached] / src / memslap.c
index 280e4c9da6cfc0414b4d5f42021fe95b8a067369..487b60230f11ddf7842b60346e75a41e0f2dfe29 100644 (file)
@@ -1,10 +1,12 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <fcntl.h>
+#include <assert.h>
 #include <sys/time.h>
 #include <getopt.h>
 #include <pthread.h>
@@ -309,12 +311,14 @@ void *run_task(void *p)
 {
   thread_context_st *context= (thread_context_st *)p;
   memcached_st *memc;
+  unsigned int value= 1;
 
   memc= memcached_create(NULL);
+  WATCHPOINT_ASSERT(memc);
   if (opt_non_blocking_io)
-    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL );
+    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &value);
   if (opt_tcp_nodelay)
-    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL );
+    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &value);
   
   memcached_server_push(memc, context->servers);
 
@@ -336,16 +340,17 @@ void *run_task(void *p)
     break;
   }
 
-  pthread_mutex_lock(&counter_mutex);
-  thread_counter--;
-  pthread_cond_signal(&count_threshhold);
-  pthread_mutex_unlock(&counter_mutex);
   memcached_free(memc);
 
   if (context->execute_pairs)
     pairs_free(context->execute_pairs);
   free(context);
 
+  pthread_mutex_lock(&counter_mutex);
+  thread_counter--;
+  pthread_cond_signal(&count_threshhold);
+  pthread_mutex_unlock(&counter_mutex);
+
   return NULL;
 }