X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmqtt.c;h=dbef915ae4d681ba4f634e3042df52defdc7c609;hb=c89182b424bb4184bd7da3f2ab687b542ed7eea3;hp=d6bcdce7ec5f5367336ce2f2bea9ee5f919e1db0;hpb=db5881cda68a542bbdb6692036b89879edb5c7c9;p=collectd.git diff --git a/src/mqtt.c b/src/mqtt.c index d6bcdce7..dbef915a 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -36,8 +36,6 @@ #include "utils_cache.h" #include "utils_complain.h" -#include - #include #define MQTT_MAX_TOPIC_SIZE 1024 @@ -221,6 +219,7 @@ static void on_message ( if (payload == NULL) { ERROR ("mqtt plugin: malloc for payload buffer failed."); + sfree (vl.values); return; } memmove (payload, msg->payload, msg->payloadlen); @@ -558,7 +557,7 @@ static int mqtt_config_publisher (oconfig_item_t *ci) conf = calloc (1, sizeof (*conf)); if (conf == NULL) { - ERROR ("mqtt plugin: malloc failed."); + ERROR ("mqtt plugin: calloc failed."); return (-1); } conf->publish = 1; @@ -663,7 +662,7 @@ static int mqtt_config_subscriber (oconfig_item_t *ci) conf = calloc (1, sizeof (*conf)); if (conf == NULL) { - ERROR ("mqtt plugin: malloc failed."); + ERROR ("mqtt plugin: calloc failed."); return (-1); } conf->publish = 0; @@ -699,11 +698,11 @@ static int mqtt_config_subscriber (oconfig_item_t *ci) cf_util_get_string (child, &conf->host); else if (strcasecmp ("Port", child->key) == 0) { - int tmp = cf_util_get_port_number (child); - if (tmp < 0) + status = cf_util_get_port_number (child); + if (status < 0) ERROR ("mqtt plugin: Invalid port number."); else - conf->port = tmp; + conf->port = status; } else if (strcasecmp ("ClientId", child->key) == 0) cf_util_get_string (child, &conf->client_id); @@ -713,12 +712,12 @@ static int mqtt_config_subscriber (oconfig_item_t *ci) cf_util_get_string (child, &conf->password); else if (strcasecmp ("QoS", child->key) == 0) { - int tmp = -1; - status = cf_util_get_int (child, &tmp); - if ((status != 0) || (tmp < 0) || (tmp > 2)) + int qos = -1; + status = cf_util_get_int (child, &qos); + if ((status != 0) || (qos < 0) || (qos > 2)) ERROR ("mqtt plugin: Not a valid QoS setting."); else - conf->qos = tmp; + conf->qos = qos; } else if (strcasecmp ("Topic", child->key) == 0) cf_util_get_string (child, &conf->topic);