From: Florian Forster Date: Sat, 30 May 2015 21:13:42 +0000 (+0200) Subject: statsd plugin: Free latency counter and AVL trees. X-Git-Tag: collectd-5.5.1~116^2~16 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=042342e6323c10064c77800e9a8f974ba73a1294;p=collectd.git 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 --- 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);