X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libhashkit%2Fhashkit.cc;h=e397871f491eea54fe99c592bf81f1e1a162e5f3;hb=983523c4536f12781533124cb8a00a4291b8cf79;hp=7f3514d1062de0c25c42927c39586e31e884411a;hpb=a6c3e3a3d04f379b1480c8c88a8eae17e54b1449;p=m6w6%2Flibmemcached diff --git a/libhashkit/hashkit.cc b/libhashkit/hashkit.cc index 7f3514d1..e397871f 100644 --- a/libhashkit/hashkit.cc +++ b/libhashkit/hashkit.cc @@ -17,24 +17,25 @@ static inline void _hashkit_init(hashkit_st *self) self->distribution_hash.context= NULL; self->flags.is_base_same_distributed= true; + self->_key= NULL; } static inline hashkit_st *_hashkit_create(hashkit_st *self) { - if (not self) + if (self) { - self= new hashkit_st; - if (not self) + self->options.is_allocated= false; + } + else + { + self= (hashkit_st*)calloc(1, sizeof(hashkit_st)); + if (self == NULL) { return NULL; } self->options.is_allocated= true; } - else - { - self->options.is_allocated= false; - } return self; } @@ -42,8 +43,10 @@ static inline hashkit_st *_hashkit_create(hashkit_st *self) hashkit_st *hashkit_create(hashkit_st *self) { self= _hashkit_create(self); - if (not self) - return self; + if (self == NULL) + { + return NULL; + } _hashkit_init(self); @@ -53,9 +56,15 @@ hashkit_st *hashkit_create(hashkit_st *self) void hashkit_free(hashkit_st *self) { + if (self and self->_key) + { + free(self->_key); + self->_key= NULL; + } + if (hashkit_is_allocated(self)) { - delete self; + free(self); } } @@ -78,6 +87,7 @@ hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *source) destination->base_hash= source->base_hash; destination->distribution_hash= source->distribution_hash; destination->flags= source->flags; + destination->_key= aes_clone_key(static_cast(source->_key)); return destination; }