From 75f7ab28d20ba0d099e23568109f3f3e6cd95d1b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 5 Jan 2021 00:03:31 +0100 Subject: [PATCH] lib/unit tests: add missing curl_global_cleanup() calls --- tests/data/test558 | 2 ++ tests/libtest/lib1502.c | 15 +++++++------- tests/libtest/lib1568.c | 2 ++ tests/libtest/lib1905.c | 11 ++++++++--- tests/libtest/lib1911.c | 6 ++++-- tests/libtest/lib543.c | 43 +++++++++++++++++++++-------------------- tests/unit/unit1302.c | 6 ++++-- tests/unit/unit1303.c | 6 ++++-- tests/unit/unit1305.c | 6 ++++-- tests/unit/unit1600.c | 6 ++++-- tests/unit/unit1605.c | 6 ++++-- tests/unit/unit1606.c | 6 ++++-- tests/unit/unit1608.c | 4 ++-- tests/unit/unit1652.c | 6 ++++-- tests/unit/unit1654.c | 3 ++- tests/unit/unit1660.c | 8 +++++++- 16 files changed, 85 insertions(+), 51 deletions(-) diff --git a/tests/data/test558 b/tests/data/test558 index f313e813a..d1ff65608 100644 --- a/tests/data/test558 +++ b/tests/data/test558 @@ -36,11 +36,13 @@ nothing # Verify data after the test has been "shot" +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() s/^MEM escape.c:\d+ free\(\(nil\)\)[\n]$// diff --git a/tests/libtest/lib1502.c b/tests/libtest/lib1502.c index d10de9771..32d4cb2c0 100644 --- a/tests/libtest/lib1502.c +++ b/tests/libtest/lib1502.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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; } diff --git a/tests/libtest/lib1568.c b/tests/libtest/lib1568.c index 2e5d88c70..87251d96f 100644 --- a/tests/libtest/lib1568.c +++ b/tests/libtest/lib1568.c @@ -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; } diff --git a/tests/libtest/lib1905.c b/tests/libtest/lib1905.c index ab8e25425..bc1acf846 100644 --- a/tests/libtest/lib1905.c +++ b/tests/libtest/lib1905.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2019 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 2019 - 2021, Daniel Stenberg, , 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; diff --git a/tests/libtest/lib1911.c b/tests/libtest/lib1911.c index 6d79bd898..09757fba8 100644 --- a/tests/libtest/lib1911.c +++ b/tests/libtest/lib1911.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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); diff --git a/tests/libtest/lib543.c b/tests/libtest/lib543.c index 10270dfa9..39bcbad1c 100644 --- a/tests/libtest/lib543.c +++ b/tests/libtest/lib543.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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; } diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c index 8cc485d58..af337cedf 100644 --- a/tests/unit/unit1302.c +++ b/tests/unit/unit1302.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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; } diff --git a/tests/unit/unit1303.c b/tests/unit/unit1303.c index 16ec09816..4c25fb963 100644 --- a/tests/unit/unit1303.c +++ b/tests/unit/unit1303.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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; } diff --git a/tests/unit/unit1305.c b/tests/unit/unit1305.c index 2432ebef2..b0e8eda5e 100644 --- a/tests/unit/unit1305.c +++ b/tests/unit/unit1305.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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) { diff --git a/tests/unit/unit1600.c b/tests/unit/unit1600.c index a76fab270..506a120b2 100644 --- a/tests/unit/unit1600.c +++ b/tests/unit/unit1600.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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; } diff --git a/tests/unit/unit1605.c b/tests/unit/unit1605.c index 9a77da2f0..26115a834 100644 --- a/tests/unit/unit1605.c +++ b/tests/unit/unit1605.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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; } diff --git a/tests/unit/unit1606.c b/tests/unit/unit1606.c index 7ef344b2c..8dee3b46e 100644 --- a/tests/unit/unit1606.c +++ b/tests/unit/unit1606.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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; } diff --git a/tests/unit/unit1608.c b/tests/unit/unit1608.c index 5243cd7cd..45ca7a3a8 100644 --- a/tests/unit/unit1608.c +++ b/tests/unit/unit1608.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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 diff --git a/tests/unit/unit1652.c b/tests/unit/unit1652.c index 2500ce95f..66f482125 100644 --- a/tests/unit/unit1652.c +++ b/tests/unit/unit1652.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, , 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; diff --git a/tests/unit/unit1654.c b/tests/unit/unit1654.c index 667551ce9..acd2cd62f 100644 --- a/tests/unit/unit1654.c +++ b/tests/unit/unit1654.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2019 - 2020, Daniel Stenberg, , et al. + * Copyright (C) 2019 - 2021, Daniel Stenberg, , 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 diff --git a/tests/unit/unit1660.c b/tests/unit/unit1660.c index 3e9b1a40e..a9b2ea075 100644 --- a/tests/unit/unit1660.c +++ b/tests/unit/unit1660.c @@ -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