Add custom memory allocation
[jansson.git] / src / hashtable.c
index d66b240..de25c21 100644 (file)
@@ -145,7 +145,7 @@ static void hashtable_do_clear(hashtable_t *hashtable)
             hashtable->free_key(pair->key);
         if(hashtable->free_value)
             hashtable->free_value(pair->value);
-        free(pair);
+        jsonp_free(pair);
     }
 }
 
@@ -155,12 +155,12 @@ static int hashtable_do_rehash(hashtable_t *hashtable)
     pair_t *pair;
     size_t i, index, new_size;
 
-    free(hashtable->buckets);
+    jsonp_free(hashtable->buckets);
 
     hashtable->num_buckets++;
     new_size = num_buckets(hashtable);
 
-    hashtable->buckets = malloc(new_size * sizeof(bucket_t));
+    hashtable->buckets = jsonp_malloc(new_size * sizeof(bucket_t));
     if(!hashtable->buckets)
         return -1;
 
@@ -187,13 +187,13 @@ static int hashtable_do_rehash(hashtable_t *hashtable)
 hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys,
                               free_fn free_key, free_fn free_value)
 {
-    hashtable_t *hashtable = malloc(sizeof(hashtable_t));
+    hashtable_t *hashtable = jsonp_malloc(sizeof(hashtable_t));
     if(!hashtable)
         return NULL;
 
     if(hashtable_init(hashtable, hash_key, cmp_keys, free_key, free_value))
     {
-        free(hashtable);
+        jsonp_free(hashtable);
         return NULL;
     }
 
@@ -203,7 +203,7 @@ hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys,
 void hashtable_destroy(hashtable_t *hashtable)
 {
     hashtable_close(hashtable);
-    free(hashtable);
+    jsonp_free(hashtable);
 }
 
 int hashtable_init(hashtable_t *hashtable,
@@ -214,7 +214,7 @@ int hashtable_init(hashtable_t *hashtable,
 
     hashtable->size = 0;
     hashtable->num_buckets = 0;  /* index to primes[] */
-    hashtable->buckets = malloc(num_buckets(hashtable) * sizeof(bucket_t));
+    hashtable->buckets = jsonp_malloc(num_buckets(hashtable) * sizeof(bucket_t));
     if(!hashtable->buckets)
         return -1;
 
@@ -237,7 +237,7 @@ int hashtable_init(hashtable_t *hashtable,
 void hashtable_close(hashtable_t *hashtable)
 {
     hashtable_do_clear(hashtable);
-    free(hashtable->buckets);
+    jsonp_free(hashtable->buckets);
 }
 
 int hashtable_set(hashtable_t *hashtable, void *key, void *value)
@@ -266,7 +266,7 @@ int hashtable_set(hashtable_t *hashtable, void *key, void *value)
     }
     else
     {
-        pair = malloc(sizeof(pair_t));
+        pair = jsonp_malloc(sizeof(pair_t));
         if(!pair)
             return -1;