Memory leak fixed.
[m6w6/libmemcached] / lib / memcached_delete.c
1 #include <memcached.h>
2
3 memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_length,
4 time_t expiration)
5 {
6 size_t send_length;
7 memcached_return rc;
8 char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
9 unsigned int server_key;
10
11 rc= memcached_connect(ptr);
12
13 if (rc != MEMCACHED_SUCCESS)
14 return rc;
15
16 server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts;
17
18 if (expiration)
19 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
20 "delete %.*s %u\r\n", key_length, key, expiration);
21 else
22 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
23 "delete %.*s\r\n", key_length, key);
24 if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
25 {
26 fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
27
28 return MEMCACHED_WRITE_FAILURE;
29 }
30
31 return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key);
32 }