hash: lazy-alloc the table in Curl_hash_add()

This makes Curl_hash_init() infallible which saves error paths.

Closes #8132
This commit is contained in:
Daniel Stenberg 2021-12-10 12:54:17 +01:00
parent e43ad4b474
commit 254f7bd78a
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
10 changed files with 78 additions and 83 deletions

View file

@ -46,19 +46,13 @@ static struct Curl_dns_entry *data_node;
static CURLcode unit_setup(void)
{
int rc;
data = curl_easy_init();
if(!data) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
rc = Curl_mk_dnscache(&hp);
if(rc) {
curl_easy_cleanup(data);
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
Curl_init_dnscache(&hp);
return CURLE_OK;
}

View file

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -38,8 +38,9 @@ static void mydtor(void *p)
static CURLcode unit_setup(void)
{
return Curl_hash_init(&hash_static, 7, Curl_hash_str,
Curl_str_key_compare, mydtor);
Curl_hash_init(&hash_static, 7, Curl_hash_str,
Curl_str_key_compare, mydtor);
return CURLE_OK;
}
static void unit_stop(void)

View file

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2015 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2015 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -39,8 +39,9 @@ static void mydtor(void *p)
static CURLcode unit_setup(void)
{
return Curl_hash_init(&hash_static, slots, Curl_hash_str,
Curl_str_key_compare, mydtor);
Curl_hash_init(&hash_static, slots, Curl_hash_str,
Curl_str_key_compare, mydtor);
return CURLE_OK;
}
static void unit_stop(void)