X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcurl_json.c;h=b19730b855a47706be9313740dc685cd4e1ac133;hb=12f249b209d7fa31e3a9d53315e47a2342463e0f;hp=4fa6f33bc6ce1e55c213fbcfbe8bbbdd4cc75f07;hpb=1ebf2f31bd2e080e6f42de640f0a3899a61501c0;p=collectd.git diff --git a/src/curl_json.c b/src/curl_json.c index 4fa6f33b..b19730b8 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -116,7 +116,7 @@ static size_t cj_curl_callback (void *buf, /* {{{ */ len = size * nmemb; - if (len <= 0) + if (len == 0) return (len); db = user_data; @@ -446,16 +446,19 @@ static c_avl_tree_t *cj_avl_create(void) static int cj_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */ oconfig_item_t *ci) { + struct curl_slist *temp = NULL; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("curl_json plugin: `%s' needs exactly one string argument.", name); return (-1); } - *dest = curl_slist_append(*dest, ci->values[0].value.string); - if (*dest == NULL) + temp = curl_slist_append(*dest, ci->values[0].value.string); + if (temp == NULL) return (-1); + *dest = temp; + return (0); } /* }}} int cj_config_append_string */ @@ -474,13 +477,12 @@ static int cj_config_add_key (cj_t *db, /* {{{ */ return (-1); } - key = malloc (sizeof (*key)); + key = calloc (1, sizeof (*key)); if (key == NULL) { - ERROR ("curl_json plugin: malloc failed."); + ERROR ("curl_json plugin: calloc failed."); return (-1); } - memset (key, 0, sizeof (*key)); key->magic = CJ_KEY_MAGIC; if (strcasecmp ("Key", ci->key) == 0) @@ -667,13 +669,12 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ return (-1); } - db = malloc (sizeof (*db)); + db = calloc (1, sizeof (*db)); if (db == NULL) { - ERROR ("curl_json plugin: malloc failed."); + ERROR ("curl_json plugin: calloc failed."); return (-1); } - memset (db, 0, sizeof (*db)); db->timeout = -1;