X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fstatsd.c;h=d0a677e70476c79dc5fa0299c3da4af8292cdfd9;hb=aa3811995bfae69f0d1a0f897acfa4a9a4c0138a;hp=ea4123c10f6d38c6a731201981eb2aba7dff8d8c;hpb=7c702e464f9faf954c320ec5b87c4755083d82bd;p=collectd.git diff --git a/src/statsd.c b/src/statsd.c index ea4123c1..285486d8 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -29,11 +29,8 @@ #include "common.h" #include "configfile.h" #include "utils_avltree.h" -#include "utils_complain.h" #include "utils_latency.h" -#include - #include #include #include @@ -127,14 +124,13 @@ static statsd_metric_t *statsd_metric_lookup_unsafe (char const *name, /* {{{ */ return (NULL); } - metric = malloc (sizeof (*metric)); + metric = calloc (1, sizeof (*metric)); if (metric == NULL) { - ERROR ("statsd plugin: malloc failed."); + ERROR ("statsd plugin: calloc failed."); sfree (key_copy); return (NULL); } - memset (metric, 0, sizeof (*metric)); metric->type = type; metric->latency = NULL; @@ -359,7 +355,7 @@ static int statsd_handle_set (char const *name, /* {{{ */ /* Make sure metric->set exists. */ if (metric->set == NULL) - metric->set = c_avl_create ((void *) strcmp); + metric->set = c_avl_create ((int (*) (const void *, const void *)) strcmp); if (metric->set == NULL) { @@ -504,7 +500,6 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */ struct pollfd *fds = NULL; size_t fds_num = 0; - struct addrinfo ai_hints; struct addrinfo *ai_list = NULL; struct addrinfo *ai_ptr; int status; @@ -513,13 +508,11 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */ char const *service = (conf_service != NULL) ? conf_service : STATSD_DEFAULT_SERVICE; - memset (&ai_hints, 0, sizeof (ai_hints)); - ai_hints.ai_flags = AI_PASSIVE; -#ifdef AI_ADDRCONFIG - ai_hints.ai_flags |= AI_ADDRCONFIG; -#endif - ai_hints.ai_family = AF_UNSPEC; - ai_hints.ai_socktype = SOCK_DGRAM; + struct addrinfo ai_hints = { + .ai_family = AF_UNSPEC, + .ai_flags = AI_PASSIVE | AI_ADDRCONFIG, + .ai_socktype = SOCK_DGRAM + }; status = getaddrinfo (node, service, &ai_hints, &ai_list); if (status != 0) @@ -565,6 +558,7 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */ if (tmp == NULL) { ERROR ("statsd plugin: realloc failed."); + close (fd); continue; } fds = tmp; @@ -712,7 +706,7 @@ static int statsd_init (void) /* {{{ */ { pthread_mutex_lock (&metrics_lock); if (metrics_tree == NULL) - metrics_tree = c_avl_create ((void *) strcmp); + metrics_tree = c_avl_create ((int (*) (const void *, const void *)) strcmp); if (!network_thread_running) { @@ -955,8 +949,6 @@ static int statsd_shutdown (void) /* {{{ */ void *key; void *value; - pthread_mutex_lock (&metrics_lock); - if (network_thread_running) { network_thread_shutdown = 1; @@ -965,6 +957,8 @@ static int statsd_shutdown (void) /* {{{ */ } network_thread_running = 0; + pthread_mutex_lock (&metrics_lock); + while (c_avl_pick (metrics_tree, &key, &value) == 0) { sfree (key);