lib/unit tests: add missing curl_global_cleanup() calls

This commit is contained in:
Daniel Stenberg 2021-01-05 00:03:31 +01:00
parent 5808144f3c
commit 75f7ab28d2
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
16 changed files with 85 additions and 51 deletions

View File

@ -36,11 +36,13 @@ nothing
# Verify data after the test has been "shot"
<verify>
<file name="log/memdump">
MEM easy.c: malloc()
MEM lib558.c: malloc()
MEM lib558.c: free()
MEM dynbuf.c: realloc()
MEM dynbuf.c: realloc()
MEM escape.c: free()
MEM easy.c: free()
</file>
<stripfile>
s/^MEM escape.c:\d+ free\(\(nil\)\)[\n]$//

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
@ -50,6 +50,11 @@ int test(char *URL)
/* DNS cache injection */
struct curl_slist *dns_cache_list;
res_global_init(CURL_GLOBAL_ALL);
if(res) {
return res;
}
msnprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2,
libtest_arg3);
@ -58,15 +63,10 @@ int test(char *URL)
dns_cache_list = curl_slist_append(NULL, redirect);
if(!dns_cache_list) {
fprintf(stderr, "curl_slist_append() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
res_global_init(CURL_GLOBAL_ALL);
if(res) {
curl_slist_free_all(dns_cache_list);
return res;
}
easy_init(easy);
easy_setopt(easy, CURLOPT_URL, URL);
@ -81,6 +81,7 @@ int test(char *URL)
else {
curl_slist_free_all(dns_cache_list);
curl_easy_cleanup(easy);
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}

View File

@ -28,6 +28,7 @@ int test(char *URL)
{
CURLcode ret;
CURL *hnd;
curl_global_init(CURL_GLOBAL_ALL);
hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_URL, URL);
@ -44,6 +45,7 @@ int test(char *URL)
curl_easy_cleanup(hnd);
hnd = NULL;
curl_global_cleanup();
return (int)ret;
}

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2019 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2019 - 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
@ -30,10 +30,15 @@ int test(char *URL)
CURLSH *sh = NULL;
CURL *ch = NULL;
int unfinished;
CURLM *cm;
CURLM *cm = curl_multi_init();
if(!cm)
curl_global_init(CURL_GLOBAL_ALL);
cm = curl_multi_init();
if(!cm) {
curl_global_cleanup();
return 1;
}
sh = curl_share_init();
if(!sh)
goto cleanup;

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
@ -40,8 +40,10 @@ int test(char *URL)
curl_global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy)
if(!easy) {
curl_global_cleanup();
return 1;
}
/* make it a zero terminated C string with just As */
memset(buffer, 'A', MAX_INPUT_LENGTH + 1);

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
@ -42,31 +42,32 @@ int test(char *URL)
easy = curl_easy_init();
if(!easy) {
fprintf(stderr, "curl_easy_init() failed\n");
return TEST_ERR_MAJOR_BAD;
res = TEST_ERR_MAJOR_BAD;
}
else {
asize = (int)sizeof(a);
asize = (int)sizeof(a);
s = curl_easy_escape(easy, (const char *)a, asize);
s = curl_easy_escape(easy, (const char *)a, asize);
if(s) {
printf("%s\n", s);
curl_free(s);
}
if(s) {
printf("%s\n", s);
curl_free(s);
s = curl_easy_escape(easy, "", 0);
if(s) {
printf("IN: '' OUT: '%s'\n", s);
curl_free(s);
}
s = curl_easy_escape(easy, " 123", 3);
if(s) {
printf("IN: ' 12' OUT: '%s'\n", s);
curl_free(s);
}
curl_easy_cleanup(easy);
}
s = curl_easy_escape(easy, "", 0);
if(s) {
printf("IN: '' OUT: '%s'\n", s);
curl_free(s);
}
s = curl_easy_escape(easy, " 123", 3);
if(s) {
printf("IN: ' 12' OUT: '%s'\n", s);
curl_free(s);
}
curl_easy_cleanup(easy);
curl_global_cleanup();
return 0;
return (int)res;
}

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
@ -34,8 +34,10 @@ static CURLcode unit_setup(void)
global_init(CURL_GLOBAL_ALL);
data = curl_easy_init();
if(!data)
if(!data) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}

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
@ -33,8 +33,10 @@ static CURLcode unit_setup(void)
global_init(CURL_GLOBAL_ALL);
data = curl_easy_init();
if(!data)
if(!data) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}

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
@ -48,8 +48,10 @@ static CURLcode unit_setup(void)
{
int rc;
data = curl_easy_init();
if(!data)
if(!data) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
rc = Curl_mk_dnscache(&hp);
if(rc) {

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
@ -32,8 +32,10 @@ static CURLcode unit_setup(void)
global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy)
if(!easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}

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
@ -31,8 +31,10 @@ static CURLcode unit_setup(void)
global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy)
if(!easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}

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
@ -32,8 +32,10 @@ static CURLcode unit_setup(void)
global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy)
if(!easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}

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
@ -41,7 +41,7 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
curl_global_cleanup();
}
UNITTEST_START

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
@ -63,8 +63,10 @@ unit_setup(void)
global_init(CURL_GLOBAL_ALL);
data = curl_easy_init();
if(!data)
if(!data) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
curl_easy_setopt(data, CURLOPT_DEBUGFUNCTION, debugf_cb);
curl_easy_setopt(data, CURLOPT_VERBOSE, 1L);
return CURLE_OK;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2019 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2019 - 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
@ -133,6 +133,7 @@ UNITTEST_START
curl_global_cleanup();
fail:
Curl_altsvc_cleanup(&asi);
curl_global_cleanup();
return unitfail;
}
UNITTEST_STOP

View File

@ -125,9 +125,14 @@ UNITTEST_START
CURL *easy;
if(!h)
return 1;
curl_global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy)
if(!easy) {
Curl_hsts_cleanup(&h);
curl_global_cleanup();
return 1;
}
Curl_hsts_loadfile(easy, h, "log/input1660");
@ -165,6 +170,7 @@ UNITTEST_START
(void)Curl_hsts_save(easy, h, "log/hsts1660");
Curl_hsts_cleanup(&h);
curl_easy_cleanup(easy);
curl_global_cleanup();
return unitfail;
}
UNITTEST_STOP