Simply free so that we can not have a bunch of if/else around using custom/not custom...
[m6w6/libmemcached] / libmemcached / memory.h
index 7b30e3711314b5cd731ffab7cce81d8dbbed45c9..65d06b8c77a2b8940485db8d43d7258513372933 100644 (file)
 
 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);
 }