diff options
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r-- | plugins/check_curl.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index a49cac8..1127d60 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -160,6 +160,8 @@ char *http_method = NULL; | |||
160 | char *http_post_data = NULL; | 160 | char *http_post_data = NULL; |
161 | char *http_content_type = NULL; | 161 | char *http_content_type = NULL; |
162 | CURL *curl; | 162 | CURL *curl; |
163 | int curl_global_initialized = 0; | ||
164 | int curl_easy_initialized = 0; | ||
163 | struct curl_slist *header_list = NULL; | 165 | struct curl_slist *header_list = NULL; |
164 | int body_buf_initialized = 0; | 166 | int body_buf_initialized = 0; |
165 | curlhelp_write_curlbuf body_buf; | 167 | curlhelp_write_curlbuf body_buf; |
@@ -421,11 +423,17 @@ static void | |||
421 | cleanup (void) | 423 | cleanup (void) |
422 | { | 424 | { |
423 | if (status_line_initialized) curlhelp_free_statusline(&status_line); | 425 | if (status_line_initialized) curlhelp_free_statusline(&status_line); |
424 | curl_easy_cleanup (curl); | 426 | status_line_initialized = 0; |
425 | curl_global_cleanup (); | 427 | if (curl_easy_initialized) curl_easy_cleanup (curl); |
428 | curl_easy_initialized = 0; | ||
429 | if (curl_global_initialized) curl_global_cleanup (); | ||
430 | curl_global_initialized = 0; | ||
426 | if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf); | 431 | if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf); |
432 | body_buf_initialized = 0; | ||
427 | if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf); | 433 | if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf); |
434 | header_buf_initialized = 0; | ||
428 | if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf); | 435 | if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf); |
436 | put_buf_initialized = 0; | ||
429 | } | 437 | } |
430 | 438 | ||
431 | int | 439 | int |
@@ -442,11 +450,12 @@ check_http (void) | |||
442 | /* initialize curl */ | 450 | /* initialize curl */ |
443 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | 451 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) |
444 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); | 452 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); |
453 | curl_global_initialized = 1; | ||
445 | 454 | ||
446 | if ((curl = curl_easy_init()) == NULL) { | 455 | if ((curl = curl_easy_init()) == NULL) { |
447 | curl_global_cleanup (); | ||
448 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); | 456 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); |
449 | } | 457 | } |
458 | curl_easy_initialized = 1; | ||
450 | 459 | ||
451 | /* register cleanup function to shut down libcurl properly */ | 460 | /* register cleanup function to shut down libcurl properly */ |
452 | atexit (cleanup); | 461 | atexit (cleanup); |
@@ -903,6 +912,7 @@ GOT_FIRST_CERT: | |||
903 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ | 912 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ |
904 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); | 913 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); |
905 | } | 914 | } |
915 | status_line_initialized = 1; | ||
906 | 916 | ||
907 | /* get result code from cURL */ | 917 | /* get result code from cURL */ |
908 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); | 918 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); |
@@ -1234,6 +1244,7 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
1234 | * attached to the URL in Location | 1244 | * attached to the URL in Location |
1235 | */ | 1245 | */ |
1236 | 1246 | ||
1247 | cleanup (); | ||
1237 | check_http (); | 1248 | check_http (); |
1238 | } | 1249 | } |
1239 | 1250 | ||
@@ -2167,7 +2178,6 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line) | |||
2167 | 2178 | ||
2168 | first_line_len = (size_t)(first_line_end - buf); | 2179 | first_line_len = (size_t)(first_line_end - buf); |
2169 | status_line->first_line = (char *)malloc (first_line_len + 1); | 2180 | status_line->first_line = (char *)malloc (first_line_len + 1); |
2170 | status_line_initialized = 1; | ||
2171 | if (status_line->first_line == NULL) return -1; | 2181 | if (status_line->first_line == NULL) return -1; |
2172 | memcpy (status_line->first_line, buf, first_line_len); | 2182 | memcpy (status_line->first_line, buf, first_line_len); |
2173 | status_line->first_line[first_line_len] = '\0'; | 2183 | status_line->first_line[first_line_len] = '\0'; |