summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2011-10-11 19:41:30 +0200
committerYang Tse <yangsita@gmail.com>2011-10-11 19:41:30 +0200
commit584dc8b8af862f7f47a3a9f02f874ac0bd0076be (patch)
tree5e5ff41b3862251704b8f46f36bcf9052ad48e52 /lib/hash.c
parenta84b8a39224d0c668d80fed561bc89b4144edbb4 (diff)
downloadcurl-584dc8b8af862f7f47a3a9f02f874ac0bd0076be.tar.gz
OOM handling/cleanup slight adjustments
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 15b3efff6..3704eea41 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -38,11 +38,14 @@ hash_element_dtor(void *user, void *element)
struct curl_hash *h = (struct curl_hash *) user;
struct curl_hash_element *e = (struct curl_hash_element *) element;
- if(e->key)
- free(e->key);
+ Curl_safefree(e->key);
- if(e->ptr)
+ if(e->ptr) {
h->dtor(e->ptr);
+ e->ptr = NULL;
+ }
+
+ e->key_len = 0;
free(e);
}
@@ -78,13 +81,16 @@ Curl_hash_init(struct curl_hash *h,
}
free(h->table);
h->table = NULL;
+ h->slots = 0;
return 1; /* failure */
}
}
return 0; /* fine */
}
- else
+ else {
+ h->slots = 0;
return 1; /* failure */
+ }
}
struct curl_hash *
@@ -190,6 +196,7 @@ int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len)
he = le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) {
Curl_llist_remove(l, le, (void *) h);
+ --h->size;
return 0;
}
}
@@ -244,6 +251,8 @@ Curl_hash_clean(struct curl_hash *h)
free(h->table);
h->table = NULL;
+ h->size = 0;
+ h->slots = 0;
}
void