summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-12-15 15:21:13 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-12-15 15:21:13 +0000
commit947e6563674b5318b909189168a9640114d8f7ba (patch)
treecdfb13d8429d22aa782a5896f0a2616eaaac6c6c /lib/hash.c
parent50e7545118dca4bb456d7c8120ac8f2f4c5bf6f5 (diff)
downloadcurl-947e6563674b5318b909189168a9640114d8f7ba.tar.gz
make sure that hash_add() has no allocated resources left in case it
returns NULL
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 89078d1f3..786228f8b 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -156,14 +156,15 @@ Curl_hash_add(curl_hash *h, char *key, size_t key_len, void *p)
}
he = mk_hash_element(key, key_len, p);
- if (!he)
- return NULL; /* failure */
-
- if (Curl_llist_insert_next(l, l->tail, he)) {
- ++h->size;
- return p; /* return the new entry */
+ if (he) {
+ if(Curl_llist_insert_next(l, l->tail, he)) {
+ ++h->size;
+ return p; /* return the new entry */
+ }
+ /* couldn't insert it, destroy the 'he' element again */
+ hash_element_dtor(h, he);
}
-
+ h->dtor(p); /* remove the NEW entry */
return NULL; /* failure */
}