diff options
author | Yang Tse <yangsita@gmail.com> | 2011-10-10 12:27:17 +0200 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2011-10-10 12:27:17 +0200 |
commit | a84b8a39224d0c668d80fed561bc89b4144edbb4 (patch) | |
tree | 3d6d2aff702eee0f2588e2b530387f3d29d4ccd2 /tests | |
parent | acaf46640108ffc7914251b8aeb57f2aed4d13b4 (diff) |
lib540.c: OOM handling fixes making test 540 pass torture testing
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libtest/lib540.c | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c index 467e87dc4..e864947c9 100644 --- a/tests/libtest/lib540.c +++ b/tests/libtest/lib540.c @@ -37,61 +37,60 @@ #define PROXYUSERPWD libtest_arg3 #define HOST test_argv[4] +CURL *eh = NULL; + static int init(CURLM *cm, const char* url, const char* userpwd, struct curl_slist *headers) { - CURL *eh; int res; if ((eh = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); - return 1; /* failure */ + goto init_failed; } res = curl_easy_setopt(eh, CURLOPT_URL, url); - if(res) { - curl_easy_cleanup(eh); - return 1; - } + if(res) + goto init_failed; + res = curl_easy_setopt(eh, CURLOPT_PROXY, PROXY); - if(res) { - curl_easy_cleanup(eh); - return 1; - } + if(res) + goto init_failed; + res = curl_easy_setopt(eh, CURLOPT_PROXYUSERPWD, userpwd); - if(res) { - curl_easy_cleanup(eh); - return 1; - } + if(res) + goto init_failed; + res = curl_easy_setopt(eh, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY); - if(res) { - curl_easy_cleanup(eh); - return 1; - } + if(res) + goto init_failed; + res = curl_easy_setopt(eh, CURLOPT_VERBOSE, 1L); - if(res) { - curl_easy_cleanup(eh); - return 1; - } + if(res) + goto init_failed; + res = curl_easy_setopt(eh, CURLOPT_HEADER, 1L); - if(res) { - curl_easy_cleanup(eh); - return 1; - } + if(res) + goto init_failed; + res = curl_easy_setopt(eh, CURLOPT_HTTPHEADER, headers); /* custom Host: */ - if(res) { - curl_easy_cleanup(eh); - return 1; - } + if(res) + goto init_failed; if ((res = (int)curl_multi_add_handle(cm, eh)) != CURLM_OK) { - fprintf(stderr, "curl_multi_add_handle() failed, " - "with code %d\n", res); - curl_easy_cleanup(eh); - return 1; /* failure */ + fprintf(stderr, "curl_multi_add_handle() failed, with code %d\n", res); + goto init_failed; } return 0; /* success */ + +init_failed: + if(eh) { + curl_easy_cleanup(eh); + eh = NULL; + } + + return 1; /* failure */ } static int loop(CURLM *cm, const char* url, const char* userpwd, @@ -153,6 +152,7 @@ static int loop(CURLM *cm, const char* url, const char* userpwd, curl_easy_strerror(msg->data.result)); curl_multi_remove_handle(cm, e); curl_easy_cleanup(e); + eh = NULL; } else { fprintf(stderr, "E: CURLMsg (%d)\n", (int)msg->msg); @@ -204,7 +204,14 @@ int test(char *URL) test_cleanup: - curl_multi_cleanup(cm); + if(cm && eh) + curl_multi_remove_handle(cm, eh); + + if(eh) + curl_easy_cleanup(eh); + + if(cm) + curl_multi_cleanup(cm); curl_global_cleanup(); |