From 384c8f356087178e4779d99d3e0e7f25331293aa Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 25 Oct 2006 05:59:46 +0000 Subject: Use curl_global_init() and curl_global_cleanup(). Improve cleanup in case of initialization failure. --- tests/libtest/lib506.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'tests/libtest/lib506.c') diff --git a/tests/libtest/lib506.c b/tests/libtest/lib506.c index ecf17fa22..862329b72 100644 --- a/tests/libtest/lib506.c +++ b/tests/libtest/lib506.c @@ -94,9 +94,14 @@ void *fire(void *ptr) CURLcode code; struct curl_slist *headers; struct Tdata *tdata = (struct Tdata*)ptr; - CURL *curl = curl_easy_init(); + CURL *curl; int i=0; + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + return NULL; + } + headers = sethost(NULL); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, (void*)headers); @@ -143,11 +148,18 @@ int test(char *URL) user.counter = 0; printf( "GLOBAL_INIT\n" ); - curl_global_init( CURL_GLOBAL_ALL ); + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + return TEST_ERR_MAJOR_BAD; + } /* prepare share */ printf( "SHARE_INIT\n" ); - share = curl_share_init(); + if ((share = curl_share_init()) == NULL) { + fprintf(stderr, "curl_share_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } if ( CURLSHE_OK == scode ) { printf( "CURLSHOPT_LOCKFUNC\n" ); @@ -171,8 +183,10 @@ int test(char *URL) } if ( CURLSHE_OK != scode ) { + fprintf(stderr, "curl_share_setopt() failed\n"); curl_share_cleanup(share); - return 2; + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; } @@ -196,7 +210,12 @@ int test(char *URL) /* fetch a another one and save cookies */ printf( "*** run %d\n", i ); - curl = curl_easy_init(); + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_share_cleanup(share); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } url = suburl( URL, i ); headers = sethost( NULL ); -- cgit v1.2.3