Updating to TODO
[m6w6/libmemcached] / lib / memcached_result.c
index 49f44b23397e353bc64e42b6f70521274991a3bc..cf3894bef3b7545fcdaca9be56d6e1883f25b2a3 100644 (file)
@@ -17,8 +17,12 @@ memcached_result_st *memcached_result_create(memcached_st *memc,
   }
   else
   {
-    ptr= (memcached_result_st *)malloc(sizeof(memcached_result_st));
-    if (!ptr)
+    if (memc->call_malloc)
+      ptr= (memcached_result_st *)memc->call_malloc(memc, sizeof(memcached_result_st));
+    else
+      ptr= (memcached_result_st *)malloc(sizeof(memcached_result_st));
+
+    if (ptr == NULL)
       return NULL;
     memset(ptr, 0, sizeof(memcached_result_st));
     ptr->is_allocated= MEMCACHED_ALLOCATED;
@@ -34,8 +38,13 @@ memcached_result_st *memcached_result_create(memcached_st *memc,
 
 void memcached_result_free(memcached_result_st *ptr)
 {
+  if (ptr == NULL)
+    return;
+
   memcached_string_free(&ptr->value);
 
   if (ptr->is_allocated == MEMCACHED_ALLOCATED)
     free(ptr);
+  else
+    ptr->is_allocated= MEMCACHED_USED;
 }