Merge branch 'collectd-5.5'
[collectd.git] / src / write_sensu.c
index 791acb3..b09dcc8 100644 (file)
@@ -29,7 +29,6 @@
 #include "common.h"
 #include "configfile.h"
 #include "utils_cache.h"
-#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <netdb.h>
@@ -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) {
@@ -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);