Removed dumb bug concerning set (was still using a buffer).
[m6w6/libmemcached] / lib / memcached.c
1 /*
2 Memcached library
3 */
4 #include <memcached.h>
5
6 memcached_st *memcached_init(memcached_st *ptr)
7 {
8 if (!ptr)
9 {
10 ptr= (memcached_st *)malloc(sizeof(memcached_st));
11
12 if (!ptr)
13 return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
14
15 memset(ptr, 0, sizeof(memcached_st));
16 ptr->is_allocated= MEMCACHED_ALLOCATED;
17 }
18 else
19 {
20 memset(ptr, 0, sizeof(memcached_st));
21 }
22
23 return ptr;
24 }
25
26 void memcached_deinit(memcached_st *ptr)
27 {
28 unsigned int x;
29 memcached_host_st *host_ptr;
30
31 if (ptr->hosts)
32 {
33 for (x= 0; x < ptr->number_of_hosts; x++)
34 {
35 if (ptr->hosts[x].fd > 0)
36 close(ptr->hosts[x].fd);
37
38 free(ptr->hosts[x].hostname);
39 }
40
41 free(ptr->hosts);
42 }
43
44 if (ptr->is_allocated == MEMCACHED_ALLOCATED)
45 free(ptr);
46 else
47 memset(ptr, 0, sizeof(memcached_st));
48 }