Added tag 0.2 for changeset 72b98d8bc30e
[awesomized/libmemcached] / lib / memcached_flush.c
index 4ca73e30ab977126b283e2f91b5d2312126872c0..a822f4ad64d05b07eb5b881c2c68f1112df59455 100644 (file)
@@ -12,6 +12,7 @@ memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
   if (rc != MEMCACHED_SUCCESS)
     rc= MEMCACHED_SOME_ERRORS;
 
+  memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
   for (x= 0; x < ptr->number_of_hosts; x++)
   {
     if (expiration)
@@ -24,9 +25,9 @@ memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
     if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
       return MEMCACHED_WRITE_FAILURE;
 
-    if ((sent_length= write(ptr->hosts[x].fd, buffer, send_length) == -1))
-      return MEMCACHED_WRITE_FAILURE;
-    if (sent_length != send_length)
+    sent_length= write(ptr->hosts[x].fd, buffer, send_length);
+
+    if (sent_length == -1 || sent_length != send_length)
       return MEMCACHED_WRITE_FAILURE;
 
     rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);