]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib/unit tests: add missing curl_global_cleanup() calls
authorDaniel Stenberg <daniel@haxx.se>
Mon, 4 Jan 2021 23:03:31 +0000 (00:03 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 6 Jan 2021 14:13:45 +0000 (15:13 +0100)
16 files changed:
tests/data/test558
tests/libtest/lib1502.c
tests/libtest/lib1568.c
tests/libtest/lib1905.c
tests/libtest/lib1911.c
tests/libtest/lib543.c
tests/unit/unit1302.c
tests/unit/unit1303.c
tests/unit/unit1305.c
tests/unit/unit1600.c
tests/unit/unit1605.c
tests/unit/unit1606.c
tests/unit/unit1608.c
tests/unit/unit1652.c
tests/unit/unit1654.c
tests/unit/unit1660.c

index f313e813acc993594fb12ce77815eb1d16cc9d4f..d1ff65608717900b783bbb91bcfc1ce490865adb 100644 (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]$//
index d10de97716f7324b3147c0f130bcc668f6db2aca..32d4cb2c07f2cc4bcda2982f79d2ebf4f1f2d6fe 100644 (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;
   }
 
index 2e5d88c7065e9d5781dcb4e628cab0cfaf6517a9..87251d96f16d117fc512285112bcfd30773cc4b4 100644 (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;
 }
 
index ab8e25425d6b88673839d92db021f9dafebb0b56..bc1acf84649addabdae3cb75a5b25999c342da91 100644 (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;
index 6d79bd8981a89de2e4a99b54cdf9f1a6129911c5..09757fba89eb6fe7b4509cc0b99a5ebdf89b49a5 100644 (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);
index 10270dfa9484b88b3d9c1ac993ea64d66298f633..39bcbad1c2ed7414d089d955f97710952aa24774 100644 (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);
+    }
 
-  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_easy_cleanup(easy);
   curl_global_cleanup();
 
-  return 0;
+  return (int)res;
 }
index 8cc485d580acce274c6579b06e72b47df8881c5f..af337cedffb814dbe0f51f69795aadf90aaad236 100644 (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;
 }
 
index 16ec098161ef7dfaa3c33025a31667f4223c6917..4c25fb963344a46e047c929cf40055edc4576362 100644 (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;
 }
 
index 2432ebef29ea702acc0dceb9bea4300077bfbc15..b0e8eda5e31bcd22e96387cf1df273d95650545c 100644 (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) {
index a76fab270a49d78f26ccfde99631f7ff21ce17e4..506a120b2b004cd92b78799c417c1aa1f405b239 100644 (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;
 }
 
index 9a77da2f0639eabaddcf89390e0fdcfe8511f44c..26115a83496368a446f3649a9c479d1791d3e9a0 100644 (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;
 }
 
index 7ef344b2c5704917256df5bbe6630bcdd3f3206a..8dee3b46e3e9e533d30e9d57660dcbe200487593 100644 (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;
 }
 
index 5243cd7cdd4cd9635fe68a57e4c6b5a560e282ac..45ca7a3a85a6676a233ac4a3f9a8cf705f77e43b 100644 (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
index 2500ce95f430e4e489af09b2ae13b02c6890ee65..66f4821255e677320c95410beb28a884a4e4ae69 100644 (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;
index 667551ce95651af6d3343cf432834ccf96b14c45..acd2cd62f7a15bef631670afbf335c6111a5d42e 100644 (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
index 3e9b1a40e9b5570383031a204c193642418f75d0..a9b2ea075b17a5d743425a16312abca72031396f 100644 (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