]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
unit1609: fix mem-leak in OOM
authorDaniel Stenberg <daniel@haxx.se>
Thu, 12 Dec 2019 22:43:29 +0000 (23:43 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 13 Dec 2019 07:16:32 +0000 (08:16 +0100)
Closes #4709

tests/unit/unit1609.c

index 8223a147cd760d06cde203a8232b324733bb2c02..ce3ddf9d810147931101b9e2a270b6e5ce078a98 100644 (file)
@@ -100,6 +100,9 @@ UNITTEST_START
 {
   int i;
   int testnum = sizeof(tests) / sizeof(struct testcase);
+  struct Curl_multi *multi = NULL;
+  struct Curl_easy *easy = NULL;
+  struct curl_slist *list = NULL;
 
 /* important: we setup cache outside of the loop
   and also clean cache after the loop. In contrast,for example,
@@ -110,11 +113,9 @@ UNITTEST_START
     int addressnum = sizeof (tests[i].address) / sizeof (*tests[i].address);
     struct Curl_addrinfo *addr;
     struct Curl_dns_entry *dns;
-    struct curl_slist *list;
     void *entry_id;
     bool problem = false;
-    struct Curl_multi *multi;
-    struct Curl_easy *easy = curl_easy_init();
+    easy = curl_easy_init();
     if(!easy) {
       curl_global_cleanup();
       return CURLE_OUT_OF_MEMORY;
@@ -122,21 +123,23 @@ UNITTEST_START
     /* create a multi handle and add the easy handle to it so that the
        hostcache is setup */
     multi = curl_multi_init();
+    if(!multi)
+      goto error;
     curl_multi_add_handle(multi, easy);
 
     list = curl_slist_append(NULL, tests[i].optval);
     if(!list)
-        goto unit_test_abort;
+      goto error;
 
     curl_easy_setopt(easy, CURLOPT_RESOLVE, list);
 
-    Curl_loadhostpairs(easy);
+    if(Curl_loadhostpairs(easy))
+      goto error;
 
     entry_id = (void *)aprintf("%s:%d", tests[i].host, tests[i].port);
-    if(!entry_id) {
-      curl_slist_free_all(list);
-      goto unit_test_abort;
-    }
+    if(!entry_id)
+      goto error;
+
     dns = Curl_hash_pick(easy->dns.hostcache, entry_id, strlen(entry_id) + 1);
     free(entry_id);
     entry_id = NULL;
@@ -194,14 +197,22 @@ UNITTEST_START
     }
 
     curl_easy_cleanup(easy);
+    easy = NULL;
     Curl_hash_destroy(&multi->hostcache);
     curl_multi_cleanup(multi);
+    multi = NULL;
     curl_slist_free_all(list);
+    list = NULL;
 
     if(problem) {
       unitfail++;
       continue;
     }
   }
+  goto unit_test_abort;
+  error:
+  curl_easy_cleanup(easy);
+  curl_multi_cleanup(multi);
+  curl_slist_free_all(list);
 }
 UNITTEST_STOP