X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_sensu.c;h=b09dcc86424d7c3a0cbab39b5bea41c5d847c2f5;hb=00f9279d9711c9882b65d54fd72c2f25a3f403fc;hp=f7803e86a24cf1194dd7ee2d1651b1a4d8628694;hpb=9b7dee8838f56233cea2854a7ddbcad2790609ce;p=collectd.git diff --git a/src/write_sensu.c b/src/write_sensu.c index f7803e86..b09dcc86 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -29,7 +29,6 @@ #include "common.h" #include "configfile.h" #include "utils_cache.h" -#include #include #include #include @@ -329,7 +328,7 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ { char name_buffer[5 * DATA_MAX_NAME_LEN]; char service_buffer[6 * DATA_MAX_NAME_LEN]; - int i; + size_t i; char *ret_str; char *temp_str; char *value_str; @@ -456,7 +455,7 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ } // incorporate sensu tags from config if any - if (strlen(sensu_tags) != 0) { + if ((sensu_tags != NULL) && (strlen(sensu_tags) != 0)) { res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags); free(ret_str); if (res == -1) { @@ -641,7 +640,7 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */ char *ret_str; char *temp_str; int status; - int i; + size_t i; int res; // add the severity/status switch (n->severity) { @@ -680,6 +679,7 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */ char *handlers_str = build_json_str_list("handlers", &(host->notification_handlers)); if (handlers_str == NULL) { ERROR("write_sensu plugin: Unable to alloc memory"); + free(ret_str); return NULL; } // incorporate the handlers @@ -752,7 +752,7 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */ } // incorporate sensu tags from config if any - if (strlen(sensu_tags) != 0) { + if ((sensu_tags != NULL) && (strlen(sensu_tags) != 0)) { res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags); free(ret_str); if (res == -1) { @@ -781,6 +781,7 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */ char *msg = replace_json_reserved(n->message); if (msg == NULL) { ERROR("write_sensu plugin: Unable to alloc memory"); + free(ret_str); return NULL; } res = asprintf(&temp_str, "%s, \"output\": \"%s - %s\"", ret_str, severity, msg); @@ -883,7 +884,7 @@ static int sensu_write(const data_set_t *ds, /* {{{ */ int statuses[vl->values_len]; struct sensu_host *host = ud->data; gauge_t *rates = NULL; - int i; + size_t i; char *msg; pthread_mutex_lock(&host->lock); @@ -897,7 +898,7 @@ static int sensu_write(const data_set_t *ds, /* {{{ */ return -1; } } - for (i = 0; i < (size_t) vl->values_len; i++) { + for (i = 0; i < vl->values_len; i++) { msg = sensu_value_to_json(host, ds, vl, (int) i, rates, statuses[i]); if (msg == NULL) { sfree(rates);