summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a7aec0a)
raw | patch | inline | side by side (parent: a7aec0a)
author | Florian Forster <octo@collectd.org> | |
Wed, 20 Feb 2013 07:36:46 +0000 (08:36 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 20 Feb 2013 07:36:46 +0000 (08:36 +0100) |
The cURL callback may be called several times, so we need to call the
complete() function after perform() returns.
complete() function after perform() returns.
src/curl_json.c | patch | blob | history |
diff --git a/src/curl_json.c b/src/curl_json.c
index 51c1b2ed75604ab84c6e13af25dd9a15c5a14f92..a7997907b74d46bd94fa18fff6e436ca4987c006 100644 (file)
--- a/src/curl_json.c
+++ b/src/curl_json.c
status = yajl_parse(db->yajl, (unsigned char *)buf, len);
if (status == yajl_status_ok)
- {
-#if HAVE_YAJL_V2
- status = yajl_complete_parse(db->yajl);
-#else
- status = yajl_parse_complete(db->yajl);
-#endif
return (len);
- }
#if !HAVE_YAJL_V2
else if (status == yajl_status_insufficient_data)
return (len);
status = curl_easy_perform (curl);
- yajl_free (db->yajl);
- db->yajl = yprev;
-
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc);
{
ERROR ("curl_json plugin: curl_easy_perform failed with response code %ld (%s)",
rc, url);
+ yajl_free (db->yajl);
+ db->yajl = yprev;
return (-1);
}
{
ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
status, db->curl_errbuf, url);
+ yajl_free (db->yajl);
+ db->yajl = yprev;
return (-1);
}
+#if HAVE_YAJL_V2
+ status = yajl_complete_parse(db->yajl);
+#else
+ status = yajl_parse_complete(db->yajl);
+#endif
+ if (status != yajl_status_ok)
+ {
+ ERROR ("curl_json plugin: %s failed with status %i.",
+#if HAVE_YAJL_V2
+ "yajl_complete_parse",
+#else
+ "yajl_parse_complete",
+#endif
+ status);
+ }
+
+ yajl_free (db->yajl);
+ db->yajl = yprev;
+
return (0);
} /* }}} int cj_curl_perform */