diff options
author | Daniel Stenberg <daniel@haxx.se> | 2021-12-10 12:54:17 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-12-10 23:16:43 +0100 |
commit | 254f7bd78a1ab248329def2cbbbc983e7f6d2495 (patch) | |
tree | d1fd479896f6c3a666befa9e57b71252a1d91248 /lib/multi.c | |
parent | e43ad4b47442c99c95f76675a17e608610231871 (diff) | |
download | curl-254f7bd78a1ab248329def2cbbbc983e7f6d2495.tar.gz |
hash: lazy-alloc the table in Curl_hash_add()bagder/hash-lazyalloc
This makes Curl_hash_init() infallible which saves error paths.
Closes #8132
Diffstat (limited to 'lib/multi.c')
-rw-r--r-- | lib/multi.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/multi.c b/lib/multi.c index 2bda97223..f8dcc63b4 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -281,11 +281,8 @@ static struct Curl_sh_entry *sh_addentry(struct Curl_hash *sh, if(!check) return NULL; /* major failure */ - if(Curl_hash_init(&check->transfers, TRHASH_SIZE, trhash, - trhash_compare, trhash_dtor)) { - free(check); - return NULL; - } + Curl_hash_init(&check->transfers, TRHASH_SIZE, trhash, trhash_compare, + trhash_dtor); /* make/add new hash entry */ if(!Curl_hash_add(sh, (char *)&s, sizeof(curl_socket_t), check)) { @@ -352,10 +349,10 @@ static size_t hash_fd(void *key, size_t key_length, size_t slots_num) * per call." * */ -static int sh_init(struct Curl_hash *hash, int hashsize) +static void sh_init(struct Curl_hash *hash, int hashsize) { - return Curl_hash_init(hash, hashsize, hash_fd, fd_key_compare, - sh_freeentry); + Curl_hash_init(hash, hashsize, hash_fd, fd_key_compare, + sh_freeentry); } /* @@ -382,11 +379,9 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */ multi->magic = CURL_MULTI_HANDLE; - if(Curl_mk_dnscache(&multi->hostcache)) - goto error; + Curl_init_dnscache(&multi->hostcache); - if(sh_init(&multi->sockhash, hashsize)) - goto error; + sh_init(&multi->sockhash, hashsize); if(Curl_conncache_init(&multi->conn_cache, chashsize)) goto error; |