Code

curl_json, curl_xml: Fix unitialized variable
authorRainer Müller <raimue@codingfarm.de>
Sun, 10 Nov 2013 02:39:22 +0000 (03:39 +0100)
committerFlorian Forster <octo@collectd.org>
Wed, 13 Nov 2013 18:55:57 +0000 (19:55 +0100)
The variable url is used unintialized here. The code used to be the same
in both plugins, but diverged in 19808b44. The solution applied there
does not work correctly as the effective URL can only be queried after
performing the request. Instead, just use the original request URL.

Signed-off-by: Florian Forster <octo@collectd.org>
src/curl_json.c
src/curl_xml.c

index 511863e39f12e98b3914f83ebc0ba446f5db4f20..6c7cf8d87676399833d25cf9c836c1fdd999f4ab 100644 (file)
@@ -859,17 +859,17 @@ static int cj_curl_perform(cj_t *db) /* {{{ */
   int status;
   long rc;
   char *url;
-  url = NULL;
-  curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
+  url = db->url;
 
   status = curl_easy_perform (db->curl);
   if (status != CURLE_OK)
   {
     ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
-           status, db->curl_errbuf, (url != NULL) ? url : "<null>");
+           status, db->curl_errbuf, url);
     return (-1);
   }
 
+  curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
   curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc);
 
   /* The response code is zero if a non-HTTP transport was used. */
index 5adaf067a157e44220655adb79855c6fee0d3b26..5d14a1d9079810a68891697f1d10bbbffde68afe 100644 (file)
@@ -608,6 +608,7 @@ static int cx_curl_perform (cx_t *db, CURL *curl) /* {{{ */
   long rc;
   char *ptr;
   char *url;
+  url = db->url;
 
   db->buffer_fill = 0; 
   status = curl_easy_perform (curl);