]> granicus.if.org Git - curl/commitdiff
Addes OOM handling for curl_easy_setopt() calls in test
authorYang Tse <yangsita@gmail.com>
Fri, 5 Feb 2010 18:07:19 +0000 (18:07 +0000)
committerYang Tse <yangsita@gmail.com>
Fri, 5 Feb 2010 18:07:19 +0000 (18:07 +0000)
50 files changed:
tests/libtest/lib500.c
tests/libtest/lib501.c
tests/libtest/lib502.c
tests/libtest/lib503.c
tests/libtest/lib504.c
tests/libtest/lib505.c
tests/libtest/lib506.c
tests/libtest/lib507.c
tests/libtest/lib508.c
tests/libtest/lib510.c
tests/libtest/lib511.c
tests/libtest/lib513.c
tests/libtest/lib514.c
tests/libtest/lib515.c
tests/libtest/lib516.c
tests/libtest/lib518.c
tests/libtest/lib519.c
tests/libtest/lib520.c
tests/libtest/lib521.c
tests/libtest/lib523.c
tests/libtest/lib524.c
tests/libtest/lib525.c
tests/libtest/lib526.c
tests/libtest/lib530.c
tests/libtest/lib533.c
tests/libtest/lib536.c
tests/libtest/lib537.c
tests/libtest/lib539.c
tests/libtest/lib540.c
tests/libtest/lib541.c
tests/libtest/lib542.c
tests/libtest/lib543.c
tests/libtest/lib544.c
tests/libtest/lib547.c
tests/libtest/lib549.c
tests/libtest/lib552.c
tests/libtest/lib553.c
tests/libtest/lib554.c
tests/libtest/lib555.c
tests/libtest/lib556.c
tests/libtest/lib560.c
tests/libtest/lib562.c
tests/libtest/lib564.c
tests/libtest/lib566.c
tests/libtest/lib567.c
tests/libtest/lib568.c
tests/libtest/lib569.c
tests/libtest/lib570.c
tests/libtest/lib571.c
tests/libtest/test.h

index 14a8e7aebe7e0649dc6764da49d5c44e67fdb1ea..c0cc9dee5cd673a2358fc6be37c6191d1a9d6251 100644 (file)
@@ -29,8 +29,8 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   res = curl_easy_perform(curl);
 
@@ -44,6 +44,8 @@ int test(char *URL)
     }
   }
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index ff2bbb5b90ef35d7e824da5215636544cda1024f..8963fbb3913d46642403d1d4829acddab221e823 100644 (file)
@@ -30,10 +30,12 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index 85c300fbe6111fefa32feac89eedb8d17da4355f..0a0a819b07ccd552d3045f7ec65d5ac31e0ca1a6 100644 (file)
@@ -23,7 +23,7 @@
 int test(char *URL)
 {
   CURL *c;
-  CURLM *m;
+  CURLM *m = NULL;
   int res = 0;
   int running=1;
   struct timeval mp_start;
@@ -40,7 +40,7 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(c, CURLOPT_URL, URL);
+  test_setopt(c, CURLOPT_URL, URL);
 
   if ((m = curl_multi_init()) == NULL) {
     fprintf(stderr, "curl_multi_init() failed\n");
@@ -81,9 +81,13 @@ int test(char *URL)
     res = TEST_ERR_RUNS_FOREVER;
   }
 
-  curl_multi_remove_handle(m, c);
+test_cleanup:
+
+  if(m) {
+    curl_multi_remove_handle(m, c);
+    curl_multi_cleanup(m);
+  }
   curl_easy_cleanup(c);
-  curl_multi_cleanup(m);
   curl_global_cleanup();
 
   return res;
index 11f1150c06cd180c1b69023c9d4cd134cbf9b500..3e8f3dc554cec3b06ec128cc56385a723ebd619a 100644 (file)
@@ -29,7 +29,7 @@
 int test(char *URL)
 {
   CURL *c;
-  CURLM *m;
+  CURLM *m = NULL;
   int res = 0;
   int running;
   char done = FALSE;
@@ -49,12 +49,12 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
-  curl_easy_setopt(c, CURLOPT_URL, URL);
-  curl_easy_setopt(c, CURLOPT_USERPWD, "test:ing");
-  curl_easy_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing");
-  curl_easy_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L);
-  curl_easy_setopt(c, CURLOPT_HEADER, 1L);
+  test_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
+  test_setopt(c, CURLOPT_URL, URL);
+  test_setopt(c, CURLOPT_USERPWD, "test:ing");
+  test_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing");
+  test_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L);
+  test_setopt(c, CURLOPT_HEADER, 1L);
 
   if ((m = curl_multi_init()) == NULL) {
     fprintf(stderr, "curl_multi_init() failed\n");
@@ -139,9 +139,13 @@ int test(char *URL)
     res = TEST_ERR_RUNS_FOREVER;
   }
 
-  curl_multi_remove_handle(m, c);
+test_cleanup:
+
+  if(m) {
+    curl_multi_remove_handle(m, c);
+    curl_multi_cleanup(m);
+  }
   curl_easy_cleanup(c);
-  curl_multi_cleanup(m);
   curl_global_cleanup();
 
   return res;
index fece016b81a13059be0869e72d2324cf8f788f6e..5eedb9ecc39925a0698ad7dc3038d17e9f12c2bb 100644 (file)
 int test(char *URL)
 {
   CURL *c;
-  int ret=0;
-  CURLM *m;
+  int res = 0;
+  CURLM *m = NULL;
   fd_set rd, wr, exc;
-  CURLMcode res;
+  CURLMcode ret;
   char done = FALSE;
   int running;
   int max_fd;
@@ -54,9 +54,9 @@ int test(char *URL)
 
   /* the point here being that there must not run anything on the given
      proxy port */
-  curl_easy_setopt(c, CURLOPT_PROXY, libtest_arg2);
-  curl_easy_setopt(c, CURLOPT_URL, URL);
-  curl_easy_setopt(c, CURLOPT_VERBOSE, 1L);
+  test_setopt(c, CURLOPT_PROXY, libtest_arg2);
+  test_setopt(c, CURLOPT_URL, URL);
+  test_setopt(c, CURLOPT_VERBOSE, 1L);
 
   if ((m = curl_multi_init()) == NULL) {
     fprintf(stderr, "curl_multi_init() failed\n");
@@ -65,9 +65,9 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  if ((res = curl_multi_add_handle(m, c)) != CURLM_OK) {
+  if ((ret = curl_multi_add_handle(m, c)) != CURLM_OK) {
     fprintf(stderr, "curl_multi_add_handle() failed, "
-            "with code %d\n", res);
+            "with code %d\n", ret);
     curl_multi_cleanup(m);
     curl_easy_cleanup(c);
     curl_global_cleanup();
@@ -93,10 +93,10 @@ int test(char *URL)
 
     fprintf(stderr, "curl_multi_perform()\n");
 
-    res = CURLM_CALL_MULTI_PERFORM;
+    ret = CURLM_CALL_MULTI_PERFORM;
 
-    while (res == CURLM_CALL_MULTI_PERFORM) {
-      res = curl_multi_perform(m, &running);
+    while (ret == CURLM_CALL_MULTI_PERFORM) {
+      ret = curl_multi_perform(m, &running);
       if (tutil_tvdiff(tutil_tvnow(), mp_start) >
           MULTI_PERFORM_HANG_TIMEOUT) {
         mp_timedout = TRUE;
@@ -112,15 +112,15 @@ int test(char *URL)
       CURLMsg *msg = curl_multi_info_read(m, &numleft);
       fprintf(stderr, "Expected: not running\n");
       if(msg && !numleft)
-        ret = 100; /* this is where we should be */
+        res = 100; /* this is where we should be */
       else
-        ret = 99; /* not correct */
+        res = 99; /* not correct */
       break;
     }
-    fprintf(stderr, "running == %d, res == %d\n", running, res);
+    fprintf(stderr, "running == %d, ret == %d\n", running, ret);
 
-    if (res != CURLM_OK) {
-      ret = 2;
+    if (ret != CURLM_OK) {
+      res = 2;
       break;
     }
 
@@ -132,7 +132,7 @@ int test(char *URL)
     fprintf(stderr, "curl_multi_fdset()\n");
     if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
       fprintf(stderr, "unexpected failured of fdset.\n");
-      ret = 3;
+      res = 3;
       break;
     }
     rc = select_test(max_fd+1, &rd, &wr, &exc, &interval);
@@ -144,14 +144,18 @@ int test(char *URL)
     if (mp_timedout) fprintf(stderr, "mp_timedout\n");
     fprintf(stderr, "ABORTING TEST, since it seems "
             "that it would have run forever.\n");
-    ret = TEST_ERR_RUNS_FOREVER;
+    res = TEST_ERR_RUNS_FOREVER;
   }
 
-  curl_multi_remove_handle(m, c);
+test_cleanup:
+
+  if(m) {
+    curl_multi_remove_handle(m, c);
+    curl_multi_cleanup(m);
+  }
   curl_easy_cleanup(c);
-  curl_multi_cleanup(m);
   curl_global_cleanup();
 
-  return ret;
+  return res;
 }
 
index 2d2858af17b084fc785b8325627dc3e1a6f3a751..b1c6799909d6c78953c03b1828666de79d6e0bc7 100644 (file)
@@ -117,27 +117,29 @@ int test(char *URL)
   headerlist = hl;
 
   /* enable uploading */
-  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+  test_setopt(curl, CURLOPT_UPLOAD, 1L);
 
   /* enable verbose */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* specify target */
-  curl_easy_setopt(curl,CURLOPT_URL, URL);
+  test_setopt(curl,CURLOPT_URL, URL);
 
   /* pass in that last of FTP commands to run after the transfer */
-  curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
+  test_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
 
   /* now specify which file to upload */
-  curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
+  test_setopt(curl, CURLOPT_INFILE, hd_src);
 
   /* and give the size of the upload (optional) */
-  curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
+  test_setopt(curl, CURLOPT_INFILESIZE_LARGE,
                    (curl_off_t)file_info.st_size);
 
   /* Now run off and do what you've been told! */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* clean up the FTP commands list */
   curl_slist_free_all(headerlist);
 
index 823e05d3e798c3d6b1c211c37ffa2f8b98894fb5..99cf915d3303c598606935139780be87910e6179 100644 (file)
@@ -224,12 +224,12 @@ int test(char *URL)
 
   url = suburl( URL, i );
   headers = sethost( NULL );
-  curl_easy_setopt( curl, CURLOPT_HTTPHEADER, headers );
-  curl_easy_setopt( curl, CURLOPT_URL,        url );
+  test_setopt( curl, CURLOPT_HTTPHEADER, headers );
+  test_setopt( curl, CURLOPT_URL,        url );
   printf( "CURLOPT_SHARE\n" );
-  curl_easy_setopt( curl, CURLOPT_SHARE,      share );
+  test_setopt( curl, CURLOPT_SHARE,      share );
   printf( "CURLOPT_COOKIEJAR\n" );
-  curl_easy_setopt( curl, CURLOPT_COOKIEJAR,  JAR );
+  test_setopt( curl, CURLOPT_COOKIEJAR,  JAR );
 
   printf( "PERFORM\n" );
   curl_easy_perform( curl );
@@ -245,6 +245,8 @@ int test(char *URL)
     printf( "SHARE_CLEANUP failed, correct\n" );
   }
 
+test_cleanup:
+
   /* clean up last handle */
   printf( "CLEANUP\n" );
   curl_easy_cleanup( curl );
index b2fd0988888d77ee83962a49954ba4f12410d4c5..25277584059871825fb649d4e99369a8fbad5b24 100644 (file)
@@ -22,8 +22,9 @@ int test(char *URL)
   CURLM* multi;
   int still_running;
   int i = -1;
+  int res = 0;
   CURLMsg *msg;
-  CURLMcode res;
+  CURLMcode ret;
   struct timeval ml_start;
   struct timeval mp_start;
   char ml_timedout = FALSE;
@@ -47,11 +48,11 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curls, CURLOPT_URL, URL);
+  test_setopt(curls, CURLOPT_URL, URL);
 
-  if ((res = curl_multi_add_handle(multi, curls)) != CURLM_OK) {
+  if ((ret = curl_multi_add_handle(multi, curls)) != CURLM_OK) {
     fprintf(stderr, "curl_multi_add_handle() failed, "
-            "with code %d\n", res);
+            "with code %d\n", ret);
     curl_easy_cleanup(curls);
     curl_multi_cleanup(multi);
     curl_global_cleanup();
@@ -62,13 +63,13 @@ int test(char *URL)
   mp_start = tutil_tvnow();
 
   do {
-    res = curl_multi_perform(multi, &still_running);
+    ret = curl_multi_perform(multi, &still_running);
     if (tutil_tvdiff(tutil_tvnow(), mp_start) > 
         MULTI_PERFORM_HANG_TIMEOUT) {
       mp_timedout = TRUE;
       break;
     }
-  } while (res == CURLM_CALL_MULTI_PERFORM);
+  } while (ret == CURLM_CALL_MULTI_PERFORM);
 
   ml_timedout = FALSE;
   ml_start = tutil_tvnow();
@@ -103,13 +104,13 @@ int test(char *URL)
         mp_timedout = FALSE;
         mp_start = tutil_tvnow();
         do {
-          res = curl_multi_perform(multi, &still_running);
+          ret = curl_multi_perform(multi, &still_running);
           if (tutil_tvdiff(tutil_tvnow(), mp_start) > 
               MULTI_PERFORM_HANG_TIMEOUT) {
             mp_timedout = TRUE;
             break;
           }
-        } while (res == CURLM_CALL_MULTI_PERFORM);
+        } while (ret == CURLM_CALL_MULTI_PERFORM);
         break;
     }
   }
@@ -128,9 +129,14 @@ int test(char *URL)
       i = msg->data.result;
   }
 
+test_cleanup:
+
   curl_multi_cleanup(multi);
   curl_easy_cleanup(curls);
   curl_global_cleanup();
 
+  if(res)
+    i = res;
+
   return i; /* return the final return code */
 }
index 6de7e7bcda80cfaf5189434e14b87736ae594ec3..f392e414d03c6b3a2ce98937abe6071568cfc00a 100644 (file)
@@ -58,34 +58,36 @@ int test(char *URL)
   }
 
   /* First set the URL that is about to receive our POST. */
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
   /* Now specify we want to POST data */
-  curl_easy_setopt(curl, CURLOPT_POST, 1L);
+  test_setopt(curl, CURLOPT_POST, 1L);
 
 #ifdef CURL_DOES_CONVERSIONS
   /* Convert the POST data to ASCII */
-  curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
 #endif
 
   /* Set the expected POST size */
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
 
   /* we want to use our own read function */
-  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+  test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
 
   /* pointer to pass to our read function */
-  curl_easy_setopt(curl, CURLOPT_INFILE, &pooh);
+  test_setopt(curl, CURLOPT_INFILE, &pooh);
 
   /* get verbose debug output please */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* include headers in the output */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   /* Perform the request, res will get the return code */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* always cleanup */
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index e13acf4ec8a9a8ccdc0344aeaf0d43a4b73e6fcc..bb0a11f2512e13a7658fbb2327dd947345e2c9f7 100644 (file)
@@ -72,39 +72,41 @@ int test(char *URL)
   }
 
   /* First set the URL that is about to receive our POST. */
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
   /* Now specify we want to POST data */
-  curl_easy_setopt(curl, CURLOPT_POST, 1L);
+  test_setopt(curl, CURLOPT_POST, 1L);
 
 #ifdef CURL_DOES_CONVERSIONS
   /* Convert the POST data to ASCII */
-  curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
 #endif
 
   /* we want to use our own read function */
-  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+  test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
 
   /* pointer to pass to our read function */
-  curl_easy_setopt(curl, CURLOPT_INFILE, &pooh);
+  test_setopt(curl, CURLOPT_INFILE, &pooh);
 
   /* get verbose debug output please */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* include headers in the output */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   /* enforce chunked transfer by setting the header */
-  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
+  test_setopt(curl, CURLOPT_HTTPHEADER, slist);
 
 #ifdef LIB565
-  curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
-  curl_easy_setopt(curl, CURLOPT_USERPWD, "foo:bar");
+  test_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
+  test_setopt(curl, CURLOPT_USERPWD, "foo:bar");
 #endif
 
   /* Perform the request, res will get the return code */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* clean up the headers list */
   if(slist)
     curl_slist_free_all(slist);
index 0f9993db116d4cade2ba84ff3b1cbeee1f6e2f4c..0e2f3df1031aa462e5e4d6da7f21a99231817a59 100644 (file)
@@ -28,13 +28,15 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
-  curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_FILETIME, 1L);
+  test_setopt(curl, CURLOPT_NOBODY, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index e49724ca6104a7191c6903793d28cd000e46aeb9..6024563101500bcdd4809b1579646f77e3cbb64d 100644 (file)
@@ -38,29 +38,31 @@ int test(char *URL)
   }
 
   /* First set the URL that is about to receive our POST. */
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
   /* Now specify we want to POST data */
-  curl_easy_setopt(curl, CURLOPT_POST, 1L);
+  test_setopt(curl, CURLOPT_POST, 1L);
 
   /* Set the expected POST size */
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 1L);
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, 1L);
 
   /* we want to use our own read function */
-  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+  test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
 
   /* pointer to pass to our read function */
-  curl_easy_setopt(curl, CURLOPT_INFILE, NULL);
+  test_setopt(curl, CURLOPT_INFILE, NULL);
 
   /* get verbose debug output please */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* include headers in the output */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   /* Perform the request, res will get the return code */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* always cleanup */
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index 06f975f34773c967ebeae16f7a34d291635fc8e3..6a5733e99e36aed2b6d5a928560fd6ecca22dc6a 100644 (file)
@@ -29,7 +29,7 @@ int test(char *URL)
   }
 
   /* First set the URL that is about to receive our POST. */
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
   /* Based on a bug report by Niels van Tongeren on June 29, 2004:
 
@@ -40,23 +40,25 @@ int test(char *URL)
 
   */
 
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "moo");
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 3L);
-  curl_easy_setopt(curl, CURLOPT_POST, 1L);
+  test_setopt(curl, CURLOPT_POSTFIELDS, "moo");
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, 3L);
+  test_setopt(curl, CURLOPT_POST, 1L);
 
   /* this is where transfer 1 would take place, but skip that and change
      options right away instead */
 
-  curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
+  test_setopt(curl, CURLOPT_NOBODY, 1L);
 
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
+  test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
+  test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
 
   /* Now, we should be making a fine HEAD request */
 
   /* Perform the request 2, res will get the return code */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* always cleanup */
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index c85f2bed11745489f8e73b103608d4d3e0061d15..56ee68ead35336b8d67cce4d61359ce5ebfc7036 100644 (file)
@@ -29,15 +29,17 @@ int test(char *URL)
   }
 
   /* First set the URL that is about to receive our POST. */
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0L);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, 0L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
+  test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
 
   /* Now, we should be making a zero byte POST request */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* always cleanup */
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index b3c63f4b51796c24c2fee71cff00ca2dcc734faf..8721583cfbb1388441d5f026a8398a19591d4f29 100644 (file)
@@ -29,14 +29,16 @@ int test(char *URL)
   }
 
   /* First set the URL that is about to receive our POST. */
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_HTTPPOST, NULL);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_HTTPPOST, NULL);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
+  test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
 
   /* Now, we should be making a zero byte POST request */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* always cleanup */
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index a1b914916fd1cd8b3bc833d87bcb1c141c2e5749..d8310d92d46705eca197938586a5dbf0ce6c4d1a 100644 (file)
@@ -484,11 +484,13 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   close_file_descriptors();
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index 70ada8a15be7f10b4e401fad2a67358745bc9be4..66013498bf77a7abdc31d631f770332223fc17ca 100644 (file)
@@ -28,19 +28,21 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_USERPWD, "monster:underbed");
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_USERPWD, "monster:underbed");
+  test_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* get first page */
   res = curl_easy_perform(curl);
 
-  curl_easy_setopt(curl, CURLOPT_USERPWD, "anothermonster:inwardrobe");
+  test_setopt(curl, CURLOPT_USERPWD, "anothermonster:inwardrobe");
 
   /* get second page */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index 1d63881c38c0edec34be6409676311bbb62356f6..57355a58fd7a2e29e0099ddf6ba615a53a86879a 100644 (file)
@@ -28,12 +28,14 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_FILETIME, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index 60fe4d95d7d5a3b9585461e93fb671142897f02f..a51b4e83c85db18f050a7fe15affce64f6b511cc 100644 (file)
@@ -28,13 +28,15 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_PORT, atoi(libtest_arg2));
-  curl_easy_setopt(curl, CURLOPT_USERPWD, "xxx:yyy");
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_PORT, atoi(libtest_arg2));
+  test_setopt(curl, CURLOPT_USERPWD, "xxx:yyy");
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index c6011fc57d8a06381e3a88549f5aad18a54e0fa7..1dcfcd9c11fa51f776d60fa792a246d0e8e832a8 100644 (file)
@@ -28,14 +28,16 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_PORT, 19999L);
-  curl_easy_setopt(curl, CURLOPT_USERPWD, "xxx:yyy");
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_PORT, 19999L);
+  test_setopt(curl, CURLOPT_USERPWD, "xxx:yyy");
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index c8b07834a0f236e573b0531824cd980034e63eaa..0b3ec5845f03216bbd1f1a3658614adb32fdc377 100644 (file)
@@ -28,12 +28,14 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_UPLOAD, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index c503d1618527ee10ce0c603c867e084b8a7f20d5..41a519e7ee31f9d677d46aa8ad108e80033eeb4c 100644 (file)
@@ -30,7 +30,7 @@ int test(char *URL)
   struct_stat file_info;
   int running;
   char done=FALSE;
-  CURLM *m;
+  CURLM *m = NULL;
   struct timeval ml_start;
   struct timeval mp_start;
   char ml_timedout = FALSE;
@@ -72,19 +72,19 @@ int test(char *URL)
   }
 
   /* enable uploading */
-  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+  test_setopt(curl, CURLOPT_UPLOAD, 1L);
 
   /* specify target */
-  curl_easy_setopt(curl,CURLOPT_URL, URL);
+  test_setopt(curl,CURLOPT_URL, URL);
 
   /* go verbose */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* use active FTP */
-  curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
+  test_setopt(curl, CURLOPT_FTPPORT, "-");
 
   /* now specify which file to upload */
-  curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
+  test_setopt(curl, CURLOPT_READDATA, hd_src);
 
   /* NOTE: if you want this code to work on Windows with libcurl as a DLL, you
      MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to
@@ -95,7 +95,7 @@ int test(char *URL)
      option you MUST make sure that the type of the passed-in argument is a
      curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
      make sure that to pass in a type 'long' argument. */
-  curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
+  test_setopt(curl, CURLOPT_INFILESIZE_LARGE,
                    (curl_off_t)file_info.st_size);
 
   if ((m = curl_multi_init()) == NULL) {
@@ -183,16 +183,22 @@ int test(char *URL)
     res = TEST_ERR_RUNS_FOREVER;
   }
 
+test_cleanup:
+
 #ifdef LIB529
   /* test 529 */
-  curl_multi_remove_handle(m, curl);
-  curl_multi_cleanup(m);
+  if(m) {
+    curl_multi_remove_handle(m, curl);
+    curl_multi_cleanup(m);
+  }
   curl_easy_cleanup(curl);
 #else
   /* test 525 */
-  curl_multi_remove_handle(m, curl);
+  if(m)
+    curl_multi_remove_handle(m, curl);
   curl_easy_cleanup(curl);
-  curl_multi_cleanup(m);
+  if(m)
+    curl_multi_cleanup(m);
 #endif
 
   fclose(hd_src); /* close the local file */
index b4d8913376c69bdf00b69bb8198554525dbf5974..600ed65e539f35f6e4cb7e967bbc196680f18859 100644 (file)
@@ -47,7 +47,7 @@ int test(char *URL)
   CURL *curl[NUM_HANDLES];
   int running;
   char done=FALSE;
-  CURLM *m;
+  CURLM *m = NULL;
   int current=0;
   int i, j;
   struct timeval ml_start;
@@ -72,10 +72,28 @@ int test(char *URL)
       curl_global_cleanup();
       return TEST_ERR_MAJOR_BAD + i;
     }
-    curl_easy_setopt(curl[i], CURLOPT_URL, URL);
+    res = curl_easy_setopt(curl[i], CURLOPT_URL, URL);
+    if(res) {
+      fprintf(stderr, "curl_easy_setopt() failed "
+              "on handle #%d\n", i);
+      for (j=i; j >= 0; j--) {
+        curl_easy_cleanup(curl[j]);
+      }
+      curl_global_cleanup();
+      return TEST_ERR_MAJOR_BAD + i;
+    }
 
     /* go verbose */
-    curl_easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
+    res = curl_easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
+    if(res) {
+      fprintf(stderr, "curl_easy_setopt() failed "
+              "on handle #%d\n", i);
+      for (j=i; j >= 0; j--) {
+        curl_easy_cleanup(curl[j]);
+      }
+      curl_global_cleanup();
+      return TEST_ERR_MAJOR_BAD + i;
+    }
   }
 
   if ((m = curl_multi_init()) == NULL) {
@@ -142,8 +160,8 @@ int test(char *URL)
           /* make us re-use the same handle all the time, and try resetting
              the handle first too */
           curl_easy_reset(curl[0]);
-          curl_easy_setopt(curl[0], CURLOPT_URL, URL);
-          curl_easy_setopt(curl[0], CURLOPT_VERBOSE, 1L);
+          test_setopt(curl[0], CURLOPT_URL, URL);
+          test_setopt(curl[0], CURLOPT_VERBOSE, 1L);
 
           /* re-add it */
           res = (int)curl_multi_add_handle(m, curl[0]);
@@ -197,16 +215,20 @@ int test(char *URL)
     res = TEST_ERR_RUNS_FOREVER;
   }
 
+test_cleanup:
+
 #ifndef LIB527
   /* get NUM_HANDLES easy handles */
   for(i=0; i < NUM_HANDLES; i++) {
 #ifdef LIB526
-    curl_multi_remove_handle(m, curl[i]);
+    if(m)
+      curl_multi_remove_handle(m, curl[i]);
 #endif
     curl_easy_cleanup(curl[i]);
   }
 #endif
-  curl_multi_cleanup(m);
+  if(m)
+    curl_multi_cleanup(m);
 
   curl_global_cleanup();
   return res;
index d738277f23448bc46455e57e090aaef1e66d6241..ef2218834f26f9bb2bc011f48112094e9aabca93 100644 (file)
@@ -69,13 +69,47 @@ int test(char *URL)
     }
     sprintf(target_url, "%s%04i", URL, i + 1);
     target_url[sizeof(target_url) - 1] = '\0';
-    curl_easy_setopt(curl[i], CURLOPT_URL, target_url);
+
+    res = curl_easy_setopt(curl[i], CURLOPT_URL, target_url);
+    if(res) {
+      fprintf(stderr, "curl_easy_setopt() failed "
+              "on handle #%d\n", i);
+      for (j=i; j >= 0; j--) {
+        curl_multi_remove_handle(m, curl[j]);
+        curl_easy_cleanup(curl[j]);
+      }
+      curl_multi_cleanup(m);
+      curl_global_cleanup();
+      return TEST_ERR_MAJOR_BAD + i;
+    }
 
     /* go verbose */
-    curl_easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
+    res = curl_easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
+    if(res) {
+      fprintf(stderr, "curl_easy_setopt() failed "
+              "on handle #%d\n", i);
+      for (j=i; j >= 0; j--) {
+        curl_multi_remove_handle(m, curl[j]);
+        curl_easy_cleanup(curl[j]);
+      }
+      curl_multi_cleanup(m);
+      curl_global_cleanup();
+      return TEST_ERR_MAJOR_BAD + i;
+    }
 
     /* include headers */
-    curl_easy_setopt(curl[i], CURLOPT_HEADER, 1L);
+    res = curl_easy_setopt(curl[i], CURLOPT_HEADER, 1L);
+    if(res) {
+      fprintf(stderr, "curl_easy_setopt() failed "
+              "on handle #%d\n", i);
+      for (j=i; j >= 0; j--) {
+        curl_multi_remove_handle(m, curl[j]);
+        curl_easy_cleanup(curl[j]);
+      }
+      curl_multi_cleanup(m);
+      curl_global_cleanup();
+      return TEST_ERR_MAJOR_BAD + i;
+    }
 
     /* add handle to multi */
     if ((res = (int)curl_multi_add_handle(m, curl[i])) != CURLM_OK) {
@@ -163,6 +197,8 @@ int test(char *URL)
     res = TEST_ERR_RUNS_FOREVER;
   }
 
+test_cleanup:
+
   /* cleanup NUM_HANDLES easy handles */
   for(i=0; i < NUM_HANDLES; i++) {
     curl_multi_remove_handle(m, curl[i]);
index 92b371a81e4a6c6c0fe95c9a567abcd72a36f10e..810b075e59e9187d46d2bedd4add7930843e12c2 100644 (file)
@@ -28,7 +28,7 @@ int test(char *URL)
   CURL *curl;
   int running;
   char done=FALSE;
-  CURLM *m;
+  CURLM *m = NULL;
   int current=0;
   struct timeval ml_start;
   struct timeval mp_start;
@@ -46,9 +46,9 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-  curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_VERBOSE, 1);
+  test_setopt(curl, CURLOPT_FAILONERROR, 1);
 
   if ((m = curl_multi_init()) == NULL) {
     fprintf(stderr, "curl_multi_init() failed\n");
@@ -103,9 +103,9 @@ int test(char *URL)
           /* make us re-use the same handle all the time, and try resetting
              the handle first too */
           curl_easy_reset(curl);
-          curl_easy_setopt(curl, CURLOPT_URL, libtest_arg2);
-          curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-          curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+          test_setopt(curl, CURLOPT_URL, libtest_arg2);
+          test_setopt(curl, CURLOPT_VERBOSE, 1);
+          test_setopt(curl, CURLOPT_FAILONERROR, 1);
 
           /* re-add it */
           res = (int)curl_multi_add_handle(m, curl);
@@ -156,8 +156,11 @@ int test(char *URL)
     res = TEST_ERR_RUNS_FOREVER;
   }
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
-  curl_multi_cleanup(m);
+  if(m)
+    curl_multi_cleanup(m);
   curl_global_cleanup();
 
   return res;
index 016b7e922f34d79b8b1a85b39ba009458feb5f13..06d863ca99cd35912ff5ede142b11b3cf8b35d89 100644 (file)
@@ -93,9 +93,9 @@ int test(char *URL)
 
   curl_multi_setopt(multi, CURLMOPT_PIPELINING, 1L);
 
-  curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
-  curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
-  curl_easy_setopt(easy, CURLOPT_URL, URL);
+  test_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
+  test_setopt(easy, CURLOPT_FAILONERROR, 1L);
+  test_setopt(easy, CURLOPT_URL, URL);
 
   if (curl_multi_add_handle(multi, easy) != CURLM_OK) {
     printf("curl_multi_add_handle() failed\n");
@@ -108,8 +108,8 @@ int test(char *URL)
   }
   curl_easy_reset(easy);
 
-  curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
-  curl_easy_setopt(easy, CURLOPT_URL, libtest_arg2);
+  test_setopt(easy, CURLOPT_FAILONERROR, 1L);
+  test_setopt(easy, CURLOPT_URL, libtest_arg2);
 
   if (curl_multi_add_handle(multi, easy) != CURLM_OK) {
     printf("curl_multi_add_handle() 2 failed\n");
@@ -120,6 +120,9 @@ int test(char *URL)
 
     curl_multi_remove_handle(multi, easy);
   }
+
+test_cleanup:
+
   curl_easy_cleanup(easy);
   curl_multi_cleanup(multi);
   curl_global_cleanup();
index 7bb8c143652fc4c7a781bb626db494020ca8002e..791448a8666c8758d52f67299c06bf9804326c2a 100644 (file)
@@ -487,11 +487,13 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   close_file_descriptors();
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index eda78fcf48c4778497ab300cb6685f0b9f0aebb0..f7df40854d3669a83063726f58e9cd245c90553c 100644 (file)
@@ -16,8 +16,8 @@ int test(char *URL)
 {
    CURLcode res;
    CURL *curl;
-   char *newURL;
-   struct curl_slist *slist;
+   char *newURL = NULL;
+   struct curl_slist *slist = NULL;
 
    if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
      fprintf(stderr, "curl_global_init() failed\n");
@@ -33,9 +33,9 @@ int test(char *URL)
    /*
     * Begin with cURL set to use a single CWD to the URL's directory.
     */
-   curl_easy_setopt(curl, CURLOPT_URL, URL);
-   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-   curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
+   test_setopt(curl, CURLOPT_URL, URL);
+   test_setopt(curl, CURLOPT_VERBOSE, 1L);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
 
    res = curl_easy_perform(curl);
 
@@ -63,14 +63,17 @@ int test(char *URL)
      return TEST_ERR_MAJOR_BAD;
    }
 
-   curl_easy_setopt(curl, CURLOPT_URL, newURL);
-   curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
-   curl_easy_setopt(curl, CURLOPT_QUOTE, slist);
+   test_setopt(curl, CURLOPT_URL, newURL);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
+   test_setopt(curl, CURLOPT_QUOTE, slist);
 
    res = curl_easy_perform(curl);
 
+test_cleanup:
+
    curl_slist_free_all(slist);
-   free(newURL);
+   if(newURL)
+     free(newURL);
    curl_easy_cleanup(curl);
    curl_global_cleanup();
 
index 1ba705a9c6cbe337549c7ee311b662738eb5d484..5fcf7bc9de34794d2cd1f4c8b1080583229332fd 100644 (file)
 #define PROXYUSERPWD libtest_arg3
 #define HOST test_argv[4]
 
-static void init(CURLM *cm, const char* url, const char* userpwd,
+static int init(CURLM *cm, const char* url, const char* userpwd,
                 struct curl_slist *headers)
 {
-  CURL *eh = curl_easy_init();
+  CURL *eh;
+  int res;
 
-  curl_easy_setopt(eh, CURLOPT_URL, url);
-  curl_easy_setopt(eh, CURLOPT_PROXY, PROXY);
-  curl_easy_setopt(eh, CURLOPT_PROXYUSERPWD, userpwd);
-  curl_easy_setopt(eh, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
-  curl_easy_setopt(eh, CURLOPT_VERBOSE, 1L);
-  curl_easy_setopt(eh, CURLOPT_HEADER, 1L);
-  curl_easy_setopt(eh, CURLOPT_HTTPHEADER, headers); /* custom Host: */
+  if ((eh = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    return 1; /* failure */
+  }
+
+  res = curl_easy_setopt(eh, CURLOPT_URL, url);
+  if(res) return 1;
+  res = curl_easy_setopt(eh, CURLOPT_PROXY, PROXY);
+  if(res) return 1;
+  res = curl_easy_setopt(eh, CURLOPT_PROXYUSERPWD, userpwd);
+  if(res) return 1;
+  res = curl_easy_setopt(eh, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
+  if(res) return 1;
+  res = curl_easy_setopt(eh, CURLOPT_VERBOSE, 1L);
+  if(res) return 1;
+  res = curl_easy_setopt(eh, CURLOPT_HEADER, 1L);
+  if(res) return 1;
+  res = curl_easy_setopt(eh, CURLOPT_HTTPHEADER, headers); /* custom Host: */
+  if(res) return 1;
+
+  if ((res = (int)curl_multi_add_handle(cm, eh)) != CURLM_OK) {
+    fprintf(stderr, "curl_multi_add_handle() failed, "
+            "with code %d\n", res);
+    return 1; /* failure */
+  }
 
-  curl_multi_add_handle(cm, eh);
+  return 0; /* success */
 }
 
 static int loop(CURLM *cm, const char* url, const char* userpwd,
@@ -50,7 +69,8 @@ static int loop(CURLM *cm, const char* url, const char* userpwd,
   fd_set R, W, E;
   struct timeval T;
 
-  init(cm, url, userpwd, headers);
+  if(init(cm, url, userpwd, headers))
+    return 1; /* failure */
 
   while (U) {
 
@@ -65,7 +85,7 @@ static int loop(CURLM *cm, const char* url, const char* userpwd,
 
       if (curl_multi_fdset(cm, &R, &W, &E, &M)) {
         fprintf(stderr, "E: curl_multi_fdset\n");
-        return EXIT_FAILURE;
+        return 1; /* failure */
       }
 
       /* In a real-world program you OF COURSE check the return that maxfd is
@@ -73,7 +93,7 @@ static int loop(CURLM *cm, const char* url, const char* userpwd,
 
       if (curl_multi_timeout(cm, &L)) {
         fprintf(stderr, "E: curl_multi_timeout\n");
-        return EXIT_FAILURE;
+        return 1; /* failure */
       }
 
       if(L != -1) {
@@ -87,7 +107,7 @@ static int loop(CURLM *cm, const char* url, const char* userpwd,
 
       if (0 > select(M+1, &R, &W, &E, &T)) {
         fprintf(stderr, "E: select\n");
-        return EXIT_FAILURE;
+        return 1; /* failure */
       }
     }
 
@@ -105,14 +125,15 @@ static int loop(CURLM *cm, const char* url, const char* userpwd,
     }
   }
 
-  return 1;
+  return 0; /* success */
 }
 
 int test(char *URL)
 {
-  CURLM *cm;
+  CURLM *cm = NULL;
   struct curl_slist *headers = NULL;
   char buffer[246]; /* naively fixed-size */
+  int res;
 
   if(test_argc < 4)
     return 99;
@@ -121,14 +142,32 @@ int test(char *URL)
 
   /* now add a custom Host: header */
   headers = curl_slist_append(headers, buffer);
+  if(!headers) {
+    fprintf(stderr, "curl_slist_append() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
 
-  curl_global_init(CURL_GLOBAL_ALL);
+  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    fprintf(stderr, "curl_global_init() failed\n");
+    curl_slist_free_all(headers);
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  if ((cm = curl_multi_init()) == NULL) {
+    fprintf(stderr, "curl_multi_init() failed\n");
+    curl_slist_free_all(headers);
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
 
-  cm = curl_multi_init();
-  loop(cm, URL, PROXYUSERPWD, headers);
+  res = loop(cm, URL, PROXYUSERPWD, headers);
+  if(res)
+    goto test_cleanup;
 
   fprintf(stderr, "lib540: now we do the request again\n");
-  loop(cm, URL, PROXYUSERPWD, headers);
+  res = loop(cm, URL, PROXYUSERPWD, headers);
+
+test_cleanup:
 
   curl_multi_cleanup(cm);
 
@@ -136,5 +175,5 @@ int test(char *URL)
 
   curl_slist_free_all(headers);
 
-  return EXIT_SUCCESS;
+  return res;
 }
index b895a25a92739a639a3ebce4d0560f0f74f347bd..9305a936c781086e92eea336928e473927c0f838 100644 (file)
@@ -90,16 +90,16 @@ int test(char *URL)
   }
 
   /* enable uploading */
-  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+  test_setopt(curl, CURLOPT_UPLOAD, 1L);
 
   /* enable verbose */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* specify target */
-  curl_easy_setopt(curl,CURLOPT_URL, URL);
+  test_setopt(curl,CURLOPT_URL, URL);
 
   /* now specify which file to upload */
-  curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
+  test_setopt(curl, CURLOPT_INFILE, hd_src);
 
   /* Now run off and do what you've been told! */
   res = curl_easy_perform(curl);
@@ -108,6 +108,8 @@ int test(char *URL)
      is at end of file */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* close the local file */
   fclose(hd_src);
 
index 9f755c9af0a2af2fac9e39ac9b2e06c794c3a0ca..585c18b3c3d1e41808d8fcf5a16aeb52db2ff4f0 100644 (file)
@@ -51,20 +51,22 @@ int test(char *URL)
   }
 
   /* enable verbose */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* enable NOBODY */
-  curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
+  test_setopt(curl, CURLOPT_NOBODY, 1L);
 
   /* disable HEADER */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
+  test_setopt(curl, CURLOPT_HEADER, 0L);
 
   /* specify target */
-  curl_easy_setopt(curl,CURLOPT_URL, URL);
+  test_setopt(curl,CURLOPT_URL, URL);
 
   /* Now run off and do what you've been told! */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index 0f97bab8da0fcfe4995344dbbb7f30754ab6d2ba..88387a1987b9e1c3857979cb719e6f475deb33c2 100644 (file)
@@ -20,11 +20,20 @@ int test(char *URL)
                        0xe0, 0xd8, 0x7c,  0x20, 0xb7, 0xef, 0x53, 0x29, 0xfa,
                        0x1d, 0x57, 0xe1};
 
-  CURL* easy  = curl_easy_init();
-  int asize = (int)sizeof(a);
-  char* s = curl_easy_escape(easy, (char*)a, asize);
+  CURL *easy;
+  int asize;
+  char *s;
   (void)URL;
 
+  if ((easy = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  asize = (int)sizeof(a);
+
+  s = curl_easy_escape(easy, (char*)a, asize);
+
   printf("%s\n", s);
 
   curl_free(s);
index b17e64af2d2b844b1300a9f41f141ecb313a366e..3229fdad34119220cc82259df1412ffac67cb64d 100644 (file)
@@ -40,16 +40,16 @@ int test(char *URL)
   }
 
   /* First set the URL that is about to receive our POST. */
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
 #ifdef LIB545
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof teststring - 1);
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof teststring - 1);
 #endif
 
-  curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, teststring);
+  test_setopt(curl, CURLOPT_COPYPOSTFIELDS, teststring);
 
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
+  test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
+  test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
 
   /* Update the original data to detect non-copy. */
   strcpy(teststring, "FAIL");
@@ -57,6 +57,8 @@ int test(char *URL)
   /* Now, this is a POST request with binary 0 embedded in POST data. */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* always cleanup */
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index a8f73eb5f31cf21eebacddd58777bcb8b63dda59..ba81b49c456d517c33c2393fd458800698610706 100644 (file)
@@ -84,29 +84,31 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 #ifdef LIB548
   /* set the data to POST with a mere pointer to a zero-terminated string */
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
+  test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
 #else
   /* 547 style, which means reading the POST data from a callback */
-  curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
-  curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
-  curl_easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
-  curl_easy_setopt(curl, CURLOPT_READDATA, &counter);
+  test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
+  test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
+  test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
+  test_setopt(curl, CURLOPT_READDATA, &counter);
   /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
 #endif
-  curl_easy_setopt(curl, CURLOPT_POST, 1L);
-  curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
-  curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
-  curl_easy_setopt(curl, CURLOPT_PROXYAUTH,
+  test_setopt(curl, CURLOPT_POST, 1L);
+  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+  test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
+  test_setopt(curl, CURLOPT_PROXYAUTH,
                    (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index e196aba56fc214f5470c1f7973825113b26443ca..4a3ee7bec30fc5d97fd34301f8e888b64d94f2ec 100644 (file)
@@ -32,16 +32,19 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_PROXY_TRANSFER_MODE, 1L);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-  if(libtest_arg3)
+  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_PROXY_TRANSFER_MODE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+  if(libtest_arg3) {
     /* enable ascii/text mode */
-    curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+    test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+  }
 
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index ce7ca1676168a63b40c47533922060c680e77973..530c5df06742d1ddf9b483be53dd776fc441b0ae 100644 (file)
@@ -155,48 +155,52 @@ int test(char *URL)
 
   config.trace_ascii = 1; /* enable ascii tracing */
 
-  curl = curl_easy_init();
-  if(curl) {
-    curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
-    curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
-    /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
-    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  if((curl = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  test_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
+  test_setopt(curl, CURLOPT_DEBUGDATA, &config);
+  /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
-    /* setup repeated data string */
-    for (i=0; i < sizeof(databuf); ++i)
-        databuf[i] = fill[i % sizeof fill];
+  /* setup repeated data string */
+  for (i=0; i < sizeof(databuf); ++i)
+      databuf[i] = fill[i % sizeof fill];
 
-    /* Post */
-    curl_easy_setopt(curl, CURLOPT_POST, 1L);
+  /* Post */
+  test_setopt(curl, CURLOPT_POST, 1L);
 
 #ifdef CURL_DOES_CONVERSIONS
-    /* Convert the POST data to ASCII */
-    curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+  /* Convert the POST data to ASCII */
+  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
 #endif
 
-    /* Setup read callback */
-    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof(databuf));
-    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+  /* Setup read callback */
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof(databuf));
+  test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
 
-    /* Write callback */
-    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
+  /* Write callback */
+  test_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
 
-    /* Ioctl function */
-    curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
+  /* Ioctl function */
+  test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
 
-    curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
 
-    curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
-    /* Accept any auth. But for this bug configure proxy with DIGEST, basic might work too, not NTLM */
-    curl_easy_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
+  /* Accept any auth. But for this bug configure proxy with DIGEST, basic might work too, not NTLM */
+  test_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
 
-    res = curl_easy_perform(curl);
-    fprintf(stderr, "curl_easy_perform = %d\n", (int)res);
+  res = curl_easy_perform(curl);
+  fprintf(stderr, "curl_easy_perform = %d\n", (int)res);
 
-    /* always cleanup */
-    curl_easy_cleanup(curl);
-  }
+test_cleanup:
+
+  curl_easy_cleanup(curl);
   curl_global_cleanup();
   return (int)res;
 }
index 7af9e4e421e4984fb4c080e44522a9f011531dd2..c5644a04d327d0ebab71bb46af2025803c90c21f 100644 (file)
@@ -49,42 +49,52 @@ int test(char *URL)
   int i;
   struct curl_slist *headerlist=NULL, *hl;
 
-  curl_global_init(CURL_GLOBAL_ALL);
-  curl = curl_easy_init();
-
-  if(curl) {
-    for (i = 0; i < NUM_HEADERS; i++) {
-      int len = sprintf(buf, "Header%d: ", i);
-      memset(&buf[len], 'A', SIZE_HEADERS);
-      buf[len + SIZE_HEADERS]=0; /* zero terminate */
-      hl = curl_slist_append(headerlist,  buf);
-      if (!hl)
-        goto errout;
-      headerlist = hl;
-    }
-    hl = curl_slist_append(headerlist, "Expect: ");
+  if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    fprintf(stderr, "curl_global_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  if((curl = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  for (i = 0; i < NUM_HEADERS; i++) {
+    int len = sprintf(buf, "Header%d: ", i);
+    memset(&buf[len], 'A', SIZE_HEADERS);
+    buf[len + SIZE_HEADERS]=0; /* zero terminate */
+    hl = curl_slist_append(headerlist,  buf);
     if (!hl)
-      goto errout;
+      goto test_cleanup;
     headerlist = hl;
+  }
 
-    curl_easy_setopt(curl, CURLOPT_URL, URL);
-    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
-    curl_easy_setopt(curl, CURLOPT_POST, 1L);
+  hl = curl_slist_append(headerlist, "Expect: ");
+  if (!hl)
+    goto test_cleanup;
+  headerlist = hl;
+
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
+  test_setopt(curl, CURLOPT_POST, 1L);
 #ifdef CURL_DOES_CONVERSIONS
-    /* Convert the POST data to ASCII */
-    curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+  /* Convert the POST data to ASCII */
+  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
 #endif
-    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
-    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-    curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
-    curl_easy_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
-    res = curl_easy_perform(curl);
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
 
-errout:
-    curl_easy_cleanup(curl);
+  res = curl_easy_perform(curl);
+
+test_cleanup:
+
+  curl_easy_cleanup(curl);
+
+  curl_slist_free_all(headerlist);
 
-    curl_slist_free_all(headerlist);
-  }
   curl_global_cleanup();
 
   return (int)res;
index 4b62e927d3676a63c92610375d4d1e360e12bac0..5a78c52cb88c2d3781faee4d7d100d14f006761e 100644 (file)
@@ -115,29 +115,31 @@ int test(char *URL)
   }
 
   /* First set the URL that is about to receive our POST. */
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
   /* Now specify we want to POST data */
-  curl_easy_setopt(curl, CURLOPT_POST, 1L);
+  test_setopt(curl, CURLOPT_POST, 1L);
 
   /* Set the expected POST size */
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
 
   /* we want to use our own read function */
-  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+  test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
 
   /* send a multi-part formpost */
-  curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
+  test_setopt(curl, CURLOPT_HTTPPOST, formpost);
 
   /* get verbose debug output please */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* include headers in the output */
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   /* Perform the request, res will get the return code */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   /* always cleanup */
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index 0b9d27ae008db7adcf14e16281879801f7582fc1..e5628a6d542c4aad2b74627d7b2116ad935e0619 100644 (file)
@@ -64,7 +64,7 @@ int test(char *URL)
   int res;
   CURL *curl;
   int counter=0;
-  CURLM *m;
+  CURLM *m = NULL;
   int running=1;
   struct timeval mp_start;
   char mp_timedout = FALSE;
@@ -80,26 +80,26 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   /* read the POST data from a callback */
-  curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
-  curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
-  curl_easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
-  curl_easy_setopt(curl, CURLOPT_READDATA, &counter);
+  test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
+  test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
+  test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
+  test_setopt(curl, CURLOPT_READDATA, &counter);
   /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
+  test_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
 
-  curl_easy_setopt(curl, CURLOPT_POST, 1L);
+  test_setopt(curl, CURLOPT_POST, 1L);
 #ifdef CURL_DOES_CONVERSIONS
   /* Convert the POST data to ASCII. */
-  curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
 #endif
-  curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
-  curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
-  curl_easy_setopt(curl, CURLOPT_PROXYAUTH,
+  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+  test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
+  test_setopt(curl, CURLOPT_PROXYAUTH,
                    (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
 
   if ((m = curl_multi_init()) == NULL) {
@@ -144,10 +144,13 @@ int test(char *URL)
     res = TEST_ERR_RUNS_FOREVER;
   }
 
-  curl_multi_remove_handle(m, curl);
-  curl_easy_cleanup(curl);
-  curl_multi_cleanup(m);
+test_cleanup:
 
+  if(m) {
+    curl_multi_remove_handle(m, curl);
+    curl_multi_cleanup(m);
+  }
+  curl_easy_cleanup(curl);
   curl_global_cleanup();
 
   return res;
index 1466e40c026dc68b3fb4e2b2d3edb76c89a7ff56..26ae30ccda8371878b83fffa314cba5688198de1 100644 (file)
@@ -39,8 +39,8 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
 
   res = curl_easy_perform(curl);
 
@@ -82,6 +82,7 @@ int test(char *URL)
     }
   }
 
+test_cleanup:
 
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index 3e34cf788c47ad8df4df534e9832cc452d27dd36..f553cc785b5dd4c4488db2c714628600ccf61cc2 100644 (file)
@@ -23,8 +23,9 @@
 int test(char *URL)
 {
   CURL *http_handle;
-  CURLM *multi_handle;
+  CURLM *multi_handle = NULL;
   CURLMcode code;
+  int res;
 
   int still_running; /* keep number of running handles */
 
@@ -33,10 +34,10 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
 
   /* set options */
-  curl_easy_setopt(http_handle, CURLOPT_URL, URL);
-  curl_easy_setopt(http_handle, CURLOPT_HEADER, 1L);
-  curl_easy_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L);
-  curl_easy_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L);
+  test_setopt(http_handle, CURLOPT_URL, URL);
+  test_setopt(http_handle, CURLOPT_HEADER, 1L);
+  test_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L);
+  test_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L);
 
   /* init a multi stack */
   multi_handle = curl_multi_init();
@@ -93,9 +94,12 @@ int test(char *URL)
     }
   }
 
-  curl_multi_cleanup(multi_handle);
+test_cleanup:
+
+  if(multi_handle)
+    curl_multi_cleanup(multi_handle);
 
   curl_easy_cleanup(http_handle);
 
-  return 0;
+  return res;
 }
index ffb0ce5f2eff87cf28f95510ea3425a7210226f0..7f84a9aad98e3c3739379a642d5eedebf95b8f42 100644 (file)
@@ -55,17 +55,19 @@ int test(char *URL)
   }
 
   /* enable verbose */
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* set port number */
-  curl_easy_setopt(curl, CURLOPT_PORT, atoi(libtest_arg2) );
+  test_setopt(curl, CURLOPT_PORT, atoi(libtest_arg2) );
 
   /* specify target */
-  curl_easy_setopt(curl,CURLOPT_URL, URL);
+  test_setopt(curl,CURLOPT_URL, URL);
 
   /* Now run off and do what you've been told! */
   res = curl_easy_perform(curl);
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index e04a5aba1af0c11ff269e77a25925c22ad2a960e..827e08dda5a6a0c3c7c0817e52531efac6eee275 100644 (file)
@@ -26,7 +26,7 @@ int test(char *URL)
   CURL *curl;
   int running;
   char done=FALSE;
-  CURLM *m;
+  CURLM *m = NULL;
   struct timeval ml_start;
   struct timeval mp_start;
   char ml_timedout = FALSE;
@@ -43,10 +43,10 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-  curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
-  curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_VERBOSE, 1);
+  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+  test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
 
   if ((m = curl_multi_init()) == NULL) {
     fprintf(stderr, "curl_multi_init() failed\n");
@@ -133,8 +133,11 @@ int test(char *URL)
     res = TEST_ERR_RUNS_FOREVER;
   }
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
-  curl_multi_cleanup(m);
+  if(m)
+    curl_multi_cleanup(m);
   curl_global_cleanup();
 
   return res;
index e2cbe7769f3162ed425592a2a32b3483d815f07f..03ad1ec755244ff6567ca58351f14950feb3f6b8 100644 (file)
@@ -30,8 +30,8 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
 
   res = curl_easy_perform(curl);
 
@@ -46,6 +46,8 @@ int test(char *URL)
     }
   }
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index e04873b113502dab0bbb13af4dc1fd98252a4b98..feae2cecf8881803f3b2248462c7f8a2c32542f8 100644 (file)
@@ -32,20 +32,23 @@ int test(char *URL)
   }
 
   /* Dump data to stdout for protocol verification */
-  curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout);
-  curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);
+  test_setopt(curl, CURLOPT_HEADERDATA, stdout);
+  test_setopt(curl, CURLOPT_WRITEDATA, stdout);
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, URL);
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
-  curl_easy_setopt(curl, CURLOPT_USERAGENT, "test567");
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, URL);
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
+  test_setopt(curl, CURLOPT_USERAGENT, "test567");
 
   custom_headers = curl_slist_append(custom_headers, "Test-Number: 567");
-  curl_easy_setopt(curl, CURLOPT_RTSPHEADER, custom_headers);
+  test_setopt(curl, CURLOPT_RTSPHEADER, custom_headers);
 
   res = curl_easy_perform(curl);
 
-  curl_slist_free_all(custom_headers);
+test_cleanup:
+
+  if(custom_headers)
+    curl_slist_free_all(custom_headers);
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index c9406b0ecd732ad94195d2affbd50e77a41b7574..0e7e3fea4460917c681b7298174d393c2cd7c080 100644 (file)
@@ -35,9 +35,9 @@ int test(char *URL)
   CURLcode res;
   CURL *curl;
   int sdp;
-  FILE *sdpf;
+  FILE *sdpf = NULL;
   struct_stat file_info;
-  char *stream_uri;
+  char *stream_uri = NULL;
   int request=1;
   struct curl_slist *custom_headers=NULL;
 
@@ -52,14 +52,18 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout);
-  curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);
+  test_setopt(curl, CURLOPT_HEADERDATA, stdout);
+  test_setopt(curl, CURLOPT_WRITEDATA, stdout);
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
+  stream_uri = NULL;
 
   sdp = open("log/file568.txt", O_RDONLY);
   fstat(sdp, &file_info);
@@ -68,65 +72,89 @@ int test(char *URL)
   sdpf = fopen("log/file568.txt", "rb");
   if(sdpf == NULL) {
     fprintf(stderr, "can't open log/file568.txt\n");
-    return TEST_ERR_MAJOR_BAD;
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
   }
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
 
-  curl_easy_setopt(curl, CURLOPT_READDATA, sdpf);
-  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
-  curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
+  test_setopt(curl, CURLOPT_READDATA, sdpf);
+  test_setopt(curl, CURLOPT_UPLOAD, 1L);
+  test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size);
 
   /* Do the ANNOUNCE */
   res = curl_easy_perform(curl);
-  if(res) {
-    fclose(sdpf);
-    return res;
-  }
+  if(res)
+    goto test_cleanup;
 
-  curl_easy_setopt(curl, CURLOPT_UPLOAD, 0L);
+  test_setopt(curl, CURLOPT_UPLOAD, 0L);
   fclose(sdpf);
+  sdpf = NULL;
 
   /* Make sure we can do a normal request now */
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
+  stream_uri = NULL;
 
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
   res = curl_easy_perform(curl);
   if(res)
-    return res;
+    goto test_cleanup;
 
   /* Now do a POST style one */
 
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
+  stream_uri = NULL;
 
   custom_headers = curl_slist_append(custom_headers,
                                      "Content-Type: posty goodness");
-
-  curl_easy_setopt(curl, CURLOPT_RTSPHEADER, custom_headers);
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
-                         "postyfield=postystuff&project=curl\n");
+  if(!custom_headers) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSPHEADER, custom_headers);
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE);
+  test_setopt(curl, CURLOPT_POSTFIELDS, "postyfield=postystuff&project=curl\n");
 
   res = curl_easy_perform(curl);
   if(res)
-    return res;
+    goto test_cleanup;
 
-  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
-  curl_easy_setopt(curl, CURLOPT_RTSPHEADER, NULL);
+  test_setopt(curl, CURLOPT_POSTFIELDS, NULL);
+  test_setopt(curl, CURLOPT_RTSPHEADER, NULL);
   curl_slist_free_all(custom_headers);
+  custom_headers = NULL;
 
   /* Make sure we can do a normal request now */
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
+  stream_uri = NULL;
 
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
   res = curl_easy_perform(curl);
-  if(res)
-    return res;
+
+test_cleanup:
+
+  if(sdpf)
+    fclose(sdpf);
+
+  if(stream_uri)
+    free(stream_uri);
+
+  if(custom_headers)
+    curl_slist_free_all(custom_headers);
 
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index 9c5d803b9f82a0180477f41232dd13a3a3c3ae2f..d5af4514ec4a222197f6926d12f5e2963255f94e 100644 (file)
@@ -31,7 +31,7 @@ int test(char *URL)
   char *rtsp_session_id;
   int request=1;
   int i;
-  FILE *idfile;
+  FILE *idfile = NULL;
 
   idfile = fopen(libtest_arg2, "wb");
   if(idfile == NULL) {
@@ -52,52 +52,63 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout);
-  curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_HEADERDATA, stdout);
+  test_setopt(curl, CURLOPT_WRITEDATA, stdout);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
   res = curl_easy_perform(curl);
   if(res != CURLE_BAD_FUNCTION_ARGUMENT) {
     fprintf(stderr, "This should have failed. "
             "Cannot setup without a Transport: header");
-    fclose(idfile);
-    return TEST_ERR_MAJOR_BAD;
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
   }
 
   /* Go through the various Session IDs */
   for(i = 0; i < 3; i++) {
-    stream_uri = suburl(URL, request++);
-    curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+    if((stream_uri = suburl(URL, request++)) == NULL) {
+      res = TEST_ERR_MAJOR_BAD;
+      goto test_cleanup;
+    }
+    test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
     free(stream_uri);
+    stream_uri = NULL;
 
-    curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
-    curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT,
-                           "Fake/NotReal/JustATest;foo=baz");
+    test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
+    test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Fake/NotReal/JustATest;foo=baz");
     res = curl_easy_perform(curl);
-    if(res) {
-      fclose(idfile);
-      return res;
-    }
+    if(res)
+      goto test_cleanup;
 
     curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id);
     fprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id);
     rtsp_session_id = NULL;
 
-    stream_uri = suburl(URL, request++);
-    curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+    if((stream_uri = suburl(URL, request++)) == NULL) {
+      res = TEST_ERR_MAJOR_BAD;
+      goto test_cleanup;
+    }
+    test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
     free(stream_uri);
+    stream_uri = NULL;
 
-    curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
-    curl_easy_perform(curl);
+    test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
+    res = curl_easy_perform(curl);
 
     /* Clear for the next go-round */
-    curl_easy_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL);
+    test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL);
   }
 
-  fclose(idfile);
+test_cleanup:
+
+  if(idfile)
+    fclose(idfile);
+
+  if(stream_uri)
+    free(stream_uri);
 
   curl_easy_cleanup(curl);
   curl_global_cleanup();
index 69a0168e0f2d2a107f5582d54b273e3dc1c91fb2..f044f85e2286ca38bccac86333c808e67348b17f 100644 (file)
@@ -25,7 +25,7 @@ int test(char *URL)
   CURLcode res;
   CURL *curl;
   int request=1;
-  char *stream_uri;
+  char *stream_uri = NULL;
 
   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     fprintf(stderr, "curl_global_init() failed\n");
@@ -38,47 +38,63 @@ int test(char *URL)
     return TEST_ERR_MAJOR_BAD;
   }
 
-  curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout);
-  curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_HEADERDATA, stdout);
+  test_setopt(curl, CURLOPT_WRITEDATA, stdout);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
 
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
+  stream_uri = NULL;
 
   res = curl_easy_perform(curl);
   if(res != CURLE_RTSP_CSEQ_ERROR) {
     fprintf(stderr, "Failed to detect CSeq mismatch");
-    return res;
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
   }
 
-  curl_easy_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 999);
-  curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT,
-                         "RAW/RAW/UDP;unicast;client_port=3056-3057");
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
+  test_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 999);
+  test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
+                    "RAW/RAW/UDP;unicast;client_port=3056-3057");
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
 
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
+  stream_uri = NULL;
 
   res = curl_easy_perform(curl);
   if(res)
-    return res;
+    goto test_cleanup;
+
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
 
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
+  stream_uri = NULL;
 
   res = curl_easy_perform(curl);
   if(res != CURLE_RTSP_SESSION_ERROR) {
     fprintf(stderr, "Failed to detect a Session ID mismatch");
   }
 
+test_cleanup:
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
index a1cd032ab659f1c09925355db9d547cebc394c80..a264eddbd9027392b16049a95fe008c6ae1b34b2 100644 (file)
@@ -91,7 +91,7 @@ int test(char *URL)
 {
   CURLcode res;
   CURL *curl;
-  char *stream_uri;
+  char *stream_uri = NULL;
   int request=1;
   FILE *protofile;
 
@@ -113,54 +113,81 @@ int test(char *URL)
     fclose(protofile);
     return TEST_ERR_MAJOR_BAD;
   }
-  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_URL, URL);
 
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
+  stream_uri = NULL;
 
-  curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
-  curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-  curl_easy_setopt(curl, CURLOPT_WRITEDATA, protofile);
+  test_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
+  test_setopt(curl, CURLOPT_TIMEOUT, 3);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_WRITEDATA, protofile);
+
+  test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "RTP/AVP/TCP;interleaved=0-1");
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
 
-  curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, "RTP/AVP/TCP;interleaved=0-1");
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
   res = curl_easy_perform(curl);
+  if(res)
+    goto test_cleanup;
 
   /* This PLAY starts the interleave */
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
+  stream_uri = NULL;
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
+
   res = curl_easy_perform(curl);
+  if(res)
+    goto test_cleanup;
 
   /* The DESCRIBE request will try to consume data after the Content */
-  stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  if((stream_uri = suburl(URL, request++)) == NULL) {
+    res = TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
+  }
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
+  stream_uri = NULL;
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
 
   res = curl_easy_perform(curl);
+  if(res)
+    goto test_cleanup;
 
   stream_uri = suburl(URL, request++);
-  curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri);
+  test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
   free(stream_uri);
-  curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
+  stream_uri = NULL;
+  test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
+
   res = curl_easy_perform(curl);
+  if(res)
+    goto test_cleanup;
 
   fprintf(stderr, "PLAY COMPLETE\n");
 
   /* Use Receive to get the rest of the data */
   while(!res && rtp_packet_count < 13) {
     fprintf(stderr, "LOOPY LOOP!\n");
-    curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
+    test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
     res = curl_easy_perform(curl);
   }
 
+test_cleanup:
+
+  fclose(protofile);
+
   curl_easy_cleanup(curl);
   curl_global_cleanup();
-  fclose(protofile);
 
   return (int)res;
 }
index 202ca7ba4ccbf41b70de9d7763afd442796536ec..3a01a07dc0c8c699875b58c3a76c24f88f01d01f 100644 (file)
@@ -42,6 +42,9 @@
 #define TEST_ERR_MAJOR_BAD     100
 #define TEST_ERR_RUNS_FOREVER   99
 
+#define test_setopt(A,B,C) \
+  if((res = curl_easy_setopt((A),(B),(C))) != CURLE_OK) goto test_cleanup
+
 extern char *libtest_arg2; /* set by first.c to the argv[2] or NULL */
 extern char *libtest_arg3; /* set by first.c to the argv[3] or NULL */