X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libhashkit%2Fhashkit.cc;h=e2528b97bdc0b32c5af39dfe62c0846a9effe9d3;hb=3347080c209fd333955a73b2798be4f98b84d27f;hp=96e39515efe9dde16cdbce1bdf43a39209ceb1e0;hpb=9a6c3f77b862f9d7bf05926989c501cac2476c71;p=awesomized%2Flibmemcached diff --git a/libhashkit/hashkit.cc b/libhashkit/hashkit.cc index 96e39515..e2528b97 100644 --- a/libhashkit/hashkit.cc +++ b/libhashkit/hashkit.cc @@ -1,11 +1,41 @@ -/* HashKit - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * HashKit library + * + * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. */ + #include static inline void _hashkit_init(hashkit_st *self) @@ -17,24 +47,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->options.is_allocated= false; + } + else { self= (hashkit_st*)calloc(1, sizeof(hashkit_st)); - if (not self) + if (self == NULL) { return NULL; } self->options.is_allocated= true; } - else - { - self->options.is_allocated= false; - } return self; } @@ -42,8 +73,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,6 +86,12 @@ 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)) { free(self); @@ -78,6 +117,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; }