X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemory.h;h=65d06b8c77a2b8940485db8d43d7258513372933;hb=60c68bea5d034012f935eb849d92781c345c7214;hp=7b30e3711314b5cd731ffab7cce81d8dbbed45c9;hpb=b16fffff43d822239ce79a366ec36873b0803df9;p=m6w6%2Flibmemcached diff --git a/libmemcached/memory.h b/libmemcached/memory.h index 7b30e371..65d06b8c 100644 --- a/libmemcached/memory.h +++ b/libmemcached/memory.h @@ -38,20 +38,42 @@ static inline void libmemcached_free(const memcached_st *self, void *mem) { - self->allocators.free(self, mem, self->allocators.context); + if (self) + { + self->allocators.free(self, mem, self->allocators.context); + } + else if (mem) + { + free(mem); + } } static inline void *libmemcached_malloc(const memcached_st *self, const size_t size) { - return self->allocators.malloc(self, size, self->allocators.context); + if (self) + { + return self->allocators.malloc(self, size, self->allocators.context); + } + + return malloc(size); } static inline void *libmemcached_realloc(const memcached_st *self, void *mem, const size_t size) { - return self->allocators.realloc(self, mem, size, self->allocators.context); + if (self) + { + return self->allocators.realloc(self, mem, size, self->allocators.context); + } + + return realloc(mem, size); } static inline void *libmemcached_calloc(const memcached_st *self, size_t nelem, size_t size) { - return self->allocators.calloc(self, nelem, size, self->allocators.context); + if (self) + { + return self->allocators.calloc(self, nelem, size, self->allocators.context); + } + + return calloc(nelem, size); }