X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_sensu.c;h=ce9efb9f3766aaab4cfae8874d39234ae5a09935;hb=13c83b972a8ade7dff6f8f2d00832d446ef6f502;hp=aae5d8bbfa73dc4929e2c51db1e5319d3807a7e4;hpb=b758f3b7146f1497d93e1df64cbc0c14ae164768;p=collectd.git diff --git a/src/write_sensu.c b/src/write_sensu.c index aae5d8bb..ce9efb9f 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -27,6 +27,7 @@ #define _GNU_SOURCE #include "collectd.h" + #include "plugin.h" #include "common.h" #include "configfile.h" @@ -35,7 +36,6 @@ #include #include #include -#include #include #include @@ -105,25 +105,25 @@ static void free_str_list(struct str_list *strs) /* {{{ */ static int sensu_connect(struct sensu_host *host) /* {{{ */ { int e; - struct addrinfo *ai, hints; + struct addrinfo *ai; char const *node; char const *service; // Resolve the target if we haven't done already if (!(host->flags & F_READY)) { - memset(&hints, 0, sizeof(hints)); memset(&service, 0, sizeof(service)); host->res = NULL; - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; -#ifdef AI_ADDRCONFIG - hints.ai_flags |= AI_ADDRCONFIG; -#endif node = (host->node != NULL) ? host->node : SENSU_HOST; service = (host->service != NULL) ? host->service : SENSU_PORT; - if ((e = getaddrinfo(node, service, &hints, &(host->res))) != 0) { + struct addrinfo ai_hints = { + .ai_family = AF_INET, + .ai_flags = AI_ADDRCONFIG, + .ai_socktype = SOCK_STREAM + }; + + if ((e = getaddrinfo(node, service, &ai_hints, &(host->res))) != 0) { ERROR("write_sensu plugin: Unable to resolve host \"%s\": %s", node, gai_strerror(e)); return -1; @@ -177,7 +177,7 @@ static void sensu_close_socket(struct sensu_host *host) /* {{{ */ static char *build_json_str_list(const char *tag, struct str_list const *list) /* {{{ */ { int res; - char *ret_str; + char *ret_str = NULL; char *temp_str; int i; if (list->nb_strs == 0) { @@ -192,6 +192,7 @@ static char *build_json_str_list(const char *tag, struct str_list const *list) / res = asprintf(&temp_str, "\"%s\": [\"%s\"", tag, list->strs[0]); if (res == -1) { ERROR("write_sensu plugin: Unable to alloc memory"); + free(ret_str); return NULL; } for (i=1; inb_strs; i++) { @@ -524,11 +525,10 @@ static char *replace_str(const char *str, const char *old, /* {{{ */ } else retlen = strlen(str); - ret = malloc(retlen + 1); + ret = calloc(1, retlen + 1); if (ret == NULL) return NULL; // added to original: not optimized, but keeps valgrind happy. - memset(ret, 0, retlen + 1); r = ret; p = str;