X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fstatsd.c;h=a0c6e4f3e935117fd9f4c428a64072e7f007bdff;hb=f3d13bd9c187c75ec9b4dbf42f8d821fb303bc90;hp=d0a677e70476c79dc5fa0299c3da4af8292cdfd9;hpb=7531a36086295c02ccb2d78c41d355a424426607;p=collectd.git diff --git a/src/statsd.c b/src/statsd.c index d0a677e7..a0c6e4f3 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) { @@ -713,7 +709,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) { @@ -956,8 +952,6 @@ static int statsd_shutdown (void) /* {{{ */ void *key; void *value; - pthread_mutex_lock (&metrics_lock); - if (network_thread_running) { network_thread_shutdown = 1; @@ -966,6 +960,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);