- * Updates to C++ interface
+ * Updates to C++ interface
+ * Custom free allocators need to now check for value before calling free.
0.49 Thu Apr 14 08:43:37 PDT 2011
* Fix calls to auto methods so that if value is not passed in nothing bad happens.
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 *)
return;
WATCHPOINT_ASSERT(array->root);
- if (array && array->root)
- {
- libmemcached_free(array->root, array);
- }
- else if (array)
- {
- free(array);
- }
+ libmemcached_free(array->root, array);
}
size_t memcached_array_size(memcached_array_st *array)
if (ptr->on_cleanup)
ptr->on_cleanup(ptr);
- if (ptr->ketama.continuum)
- libmemcached_free(ptr, ptr->ketama.continuum);
+ libmemcached_free(ptr, ptr->ketama.continuum);
memcached_array_free(ptr->prefix_key);
ptr->prefix_key= NULL;
{
ptr= (memcached_st *)malloc(sizeof(memcached_st));
- if (! ptr)
+ if (not ptr)
{
return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
}
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);
}
if (memcached_is_allocated(self))
{
- if (self->root)
- {
- libmemcached_free(self->root, self);
- }
- else
- {
- free(self);
- }
+ libmemcached_free(self->root, self);
}
else
{
}
memcached_st *root= self->root;
- if (root)
- {
- libmemcached_free(root, self);
- }
- else
- {
- free(self);
- }
+ libmemcached_free(root, self);
}
uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count)
if (memc_stat->root)
{
libmemcached_free(memc_stat->root, memc_stat);
+ return;
}
- else if (ptr)
- {
- libmemcached_free(ptr, memc_stat);
- }
- else
- {
- free(memc_stat);
- }
+
+ libmemcached_free(ptr, memc_stat);
}
static memcached_return_t call_stat_fn(memcached_st *ptr,