diff options
author | Petri Lehtinen <petri@digip.org> | 2016-08-11 22:15:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-11 22:15:01 +0300 |
commit | 71594af7d522e2bcae1cabdc975608d48de66d5e (patch) | |
tree | 82cd3c0d86515ca0a805198d2a7236295417ccb4 /src/hashtable.c | |
parent | 8f067962f6442bda65f0a8909f589f2616a42c5a (diff) | |
parent | 6a4b3f878dddb1525b59b86da7fb392ab8fdc7b2 (diff) | |
download | jansson-71594af7d522e2bcae1cabdc975608d48de66d5e.zip jansson-71594af7d522e2bcae1cabdc975608d48de66d5e.tar.gz jansson-71594af7d522e2bcae1cabdc975608d48de66d5e.tar.bz2 |
Merge pull request #298 from pasiopou/oom-crash
OOM crash
Diffstat (limited to 'src/hashtable.c')
-rw-r--r-- | src/hashtable.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/hashtable.c b/src/hashtable.c index a453b00..0ec1ef8 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -152,17 +152,20 @@ static int hashtable_do_rehash(hashtable_t *hashtable) { list_t *list, *next; pair_t *pair; - size_t i, index, new_size; + size_t i, index, new_size, new_order; + struct hashtable_bucket *new_buckets; - jsonp_free(hashtable->buckets); - - hashtable->order++; - new_size = hashsize(hashtable->order); + new_order = hashtable->order + 1; + new_size = hashsize(new_order); - hashtable->buckets = jsonp_malloc(new_size * sizeof(bucket_t)); - if(!hashtable->buckets) + new_buckets = jsonp_malloc(new_size * sizeof(bucket_t)); + if(!new_buckets) return -1; + jsonp_free(hashtable->buckets); + hashtable->buckets = new_buckets; + hashtable->order = new_order; + for(i = 0; i < hashsize(hashtable->order); i++) { hashtable->buckets[i].first = hashtable->buckets[i].last = |