]> granicus.if.org Git - curl/commitdiff
tests: fixed OOM handling of unit tests to abort test
authorDan Fandrich <dan@coneharvesters.com>
Sun, 30 Apr 2017 08:54:26 +0000 (10:54 +0200)
committerDan Fandrich <dan@coneharvesters.com>
Sun, 30 Apr 2017 08:55:20 +0000 (10:55 +0200)
It's dangerous to continue to run the test when a memory alloc fails.

tests/unit/unit1600.c
tests/unit/unit1604.c
tests/unit/unit1605.c
tests/unit/unit1606.c

index f0f9cc1f4cde5fe9f7e4da85e7debba341fb43ec..af0ad8435af50cc29c7915038eb2eca3939e03de 100644 (file)
@@ -29,7 +29,7 @@ CURL *easy;
 static CURLcode unit_setup(void)
 {
   easy = curl_easy_init();
-  return CURLE_OK;
+  return easy ? CURLE_OK : CURLE_OUT_OF_MEMORY;
 }
 
 static void unit_stop(void)
index 5f1ea95184f4a1a6e4925049511194fb78b58d42..a7c2a25437866a9e7ab258387397e5c4eafab869 100644 (file)
@@ -45,7 +45,7 @@ static void unit_stop(void)
 static char *getflagstr(int flags)
 {
   char *buf = malloc(256);
-  fail_unless(buf, "out of memory");
+  abort_unless(buf, "out of memory");
   snprintf(buf, 256, "%s,%s,%s,%s",
     ((flags & SANITIZE_ALLOW_COLONS) ? "SANITIZE_ALLOW_COLONS" : ""),
     ((flags & SANITIZE_ALLOW_PATH) ? "SANITIZE_ALLOW_PATH" : ""),
@@ -57,7 +57,7 @@ static char *getflagstr(int flags)
 static char *getcurlcodestr(int cc)
 {
   char *buf = malloc(256);
-  fail_unless(buf, "out of memory");
+  abort_unless(buf, "out of memory");
   snprintf(buf, 256, "%s (%d)",
     (cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" :
      cc == SANITIZE_ERR_BAD_ARGUMENT ? "SANITIZE_ERR_BAD_ARGUMENT" :
index c807cb3f27a0cda0927dd446ef0aa5826cce8d7c..2fe3a5acab657cb0da9372da275decb9391c867f 100644 (file)
@@ -34,9 +34,10 @@ static void unit_stop(void)
 }
 
 UNITTEST_START
-  CURL *easy = curl_easy_init();
   int len;
   char *esc;
+  CURL *easy = curl_easy_init();
+  abort_unless(easy, "out of memory");
 
   esc = curl_easy_escape(easy, "", -1);
   fail_unless(esc == NULL, "negative string length can't work");
index fdc0ec3817a1fbe1ad7e40ef42aa4e490a797290..7acba03256d38ea45fa808e68a764404feb7fb6c 100644 (file)
@@ -69,6 +69,7 @@ static int runawhile(struct Curl_easy *easy,
 UNITTEST_START
 {
   struct Curl_easy *easy = curl_easy_init();
+  abort_unless(easy, "out of memory");
 
   fail_unless(runawhile(easy, 41, 41, 40, 0) == 41,
               "wrong low speed timeout");