X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fallocators.cc;h=cc41f2c37a7bb1adddad5e6c365be07e42fb9409;hb=77e79fb2056c9a177a670da48178fd1ac051d33d;hp=d0d9e57e8659dfdd0e333ad24e310a128be1d18a;hpb=f0b9c972a973d997db6660680938dd5acb2baa46;p=m6w6%2Flibmemcached diff --git a/libmemcached/allocators.cc b/libmemcached/allocators.cc index d0d9e57e..cc41f2c3 100644 --- a/libmemcached/allocators.cc +++ b/libmemcached/allocators.cc @@ -39,7 +39,10 @@ void _libmemcached_free(const memcached_st*, void *mem, void*) { - free(mem); + if (mem) + { + free(mem); + } } void *_libmemcached_malloc(const memcached_st *, size_t size, void *) @@ -58,7 +61,9 @@ void *_libmemcached_calloc(const memcached_st *self, size_t nelem, size_t size, { void *ret = _libmemcached_malloc(self, nelem * size, context); if (not ret) + { memset(ret, 0, nelem * size); + } return ret; } @@ -79,6 +84,11 @@ memcached_return_t memcached_set_memory_allocators(memcached_st *self, memcached_calloc_fn mem_calloc, void *context) { + if (self == NULL) + { + return MEMCACHED_INVALID_ARGUMENTS; + } + /* All should be set, or none should be set */ if (mem_malloc == NULL && mem_free == NULL && mem_realloc == NULL && mem_calloc == NULL) { @@ -86,7 +96,7 @@ memcached_return_t memcached_set_memory_allocators(memcached_st *self, } else if (mem_malloc == NULL || mem_free == NULL || mem_realloc == NULL || mem_calloc == NULL) { - return MEMCACHED_FAILURE; + return memcached_set_error(*self, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("NULL parameter provided for one or more allocators")); } else { @@ -111,6 +121,11 @@ void memcached_get_memory_allocators(const memcached_st *self, memcached_realloc_fn *mem_realloc, memcached_calloc_fn *mem_calloc) { + if (self == NULL) + { + return; + } + *mem_malloc= self->allocators.malloc; *mem_free= self->allocators.free; *mem_realloc= self->allocators.realloc;