From 042342e6323c10064c77800e9a8f974ba73a1294 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 30 May 2015 23:13:42 +0200 Subject: [PATCH] statsd plugin: Free latency counter and AVL trees. latency counters (used by TIMER metrics) and AVL trees (used by SET metrics) were not freed when cleaning up unused metrics. This resulted in leaked memory. Fixes: #997 --- src/statsd.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/statsd.c b/src/statsd.c index 327b8db4..ebb7c1eb 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -190,6 +190,36 @@ static int statsd_metric_add (char const *name, double delta, /* {{{ */ return (0); } /* }}} int statsd_metric_add */ +static void statsd_metric_free (statsd_metric_t *metric) /* {{{ */ +{ + if (metric == NULL) + return; + + if (metric->latency != NULL) + { + latency_counter_destroy (metric->latency); + metric->latency = NULL; + } + + if (metric->set != NULL) + { + void *key; + void *value; + + while (c_avl_pick (metric->set, &key, &value) == 0) + { + sfree (key); + assert (value == NULL); + } + + c_avl_destroy (metric->set); + metric->set = NULL; + } + + sfree (name); + sfree (metric); +} /* }}} void statsd_metric_free */ + static int statsd_parse_value (char const *str, value_t *ret_value) /* {{{ */ { char *endptr = NULL; @@ -877,7 +907,7 @@ static int statsd_read (void) /* {{{ */ } sfree (name); - sfree (metric); + statsd_metric_free (metric); } pthread_mutex_unlock (&metrics_lock); -- 2.30.2