Merging Trond, also fixed make test.
[awesomized/libmemcached] / libmemcached / memcached_get.c
index cdfb5d29082c56366d253c826d948fa6c969015a..e91db4cf363854f3aa363691c23ece90b274c8ac 100644 (file)
@@ -368,11 +368,11 @@ static memcached_return replication_binary_mget(memcached_st *ptr,
 
   int flush= number_of_keys == 1;
 
-  for (int replica = 0; replica <= ptr->number_of_replicas; ++replica)
+  for (uint32_t replica= 0; replica <= ptr->number_of_replicas; ++replica)
   {
     bool success= true;    
     
-    for (uint32_t x= 0; x < number_of_keys; ++x)
+    for (x= 0; x < number_of_keys; ++x)
     {
       if (hash[x] == ptr->number_of_hosts)
         continue; /* Already successfully sent */
@@ -443,15 +443,14 @@ static memcached_return replication_binary_mget(memcached_st *ptr,
           memcached_server_response_increment(&ptr->hosts[x]);
 
           /* mark all of the messages bound for this server as sent! */
-          for (uint32_t x= 0; x < number_of_keys; ++x)
+          for (x= 0; x < number_of_keys; ++x)
             if (hash[x] == x)
               hash[x]= ptr->number_of_hosts;
         }
     }
 
-    if (success) {
+    if (success)
       break;
-    }
   }
 
   return rc;
@@ -465,60 +464,38 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
 {
   memcached_return rc;
 
-  if (ptr->number_of_replicas == 0) {
+  if (ptr->number_of_replicas == 0) 
+  {
     rc= simple_binary_mget(ptr, master_server_key, is_master_key_set,
                            keys, key_length, number_of_keys);
-  } else {
+  } 
+  else 
+  {
     uint32_t* hash;
     bool* dead_servers;
 
-    if (ptr->call_malloc)
-    {
-      hash= ptr->call_malloc(ptr, sizeof(uint32_t) * number_of_keys);
-      dead_servers= ptr->call_malloc(ptr, sizeof(bool) * ptr->number_of_hosts);
-    }
-    else
-    {
-      hash = malloc(sizeof(uint32_t) * number_of_keys);
-      dead_servers= malloc(sizeof(bool) * ptr->number_of_hosts);
-    }
+    hash= ptr->call_malloc(ptr, sizeof(uint32_t) * number_of_keys);
+    dead_servers= ptr->call_calloc(ptr, ptr->number_of_hosts, sizeof(bool));
 
     if (hash == NULL || dead_servers == NULL)
     {
-      if (ptr->call_free)
-      {
-        if (hash != NULL) ptr->call_free(ptr, hash);
-        if (dead_servers != NULL) ptr->call_free(ptr, dead_servers);
-      }
-      else
-      {
-        free(hash); /* No need to check for NULL (just look in the C spec) */
-        free(dead_servers);
-      }
+      ptr->call_free(ptr, hash);
+      ptr->call_free(ptr, dead_servers);
       return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
     }
 
-    memset(dead_servers, 0, sizeof(bool) * ptr->number_of_hosts);
-
     if (is_master_key_set)
-      for (unsigned int x= 0; x < number_of_keys; ++x)
+      for (unsigned int x= 0; x < number_of_keys; x++)
         hash[x]= master_server_key;
     else
-      for (unsigned int x= 0; x < number_of_keys; ++x)
+      for (unsigned int x= 0; x < number_of_keys; x++)
         hash[x]= memcached_generate_hash(ptr, keys[x], key_length[x]);
 
-    rc= replication_binary_mget(ptr, hash, dead_servers, keys, key_length, number_of_keys);
+    rc= replication_binary_mget(ptr, hash, dead_servers, keys, 
+                                key_length, number_of_keys);
 
-    if (ptr->call_free)
-    {
-      ptr->call_free(ptr, hash);
-      ptr->call_free(ptr, dead_servers);
-    }
-    else
-    {
-      free(hash);
-      free(dead_servers);
-    }
+    ptr->call_free(ptr, hash);
+    ptr->call_free(ptr, dead_servers);
 
     return MEMCACHED_SUCCESS;
   }