From eec94c8f0a11902803983efe093e4b4de9359898 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 6 Jan 2016 16:00:32 +0000 Subject: [PATCH] Add cleanup code for statistics --- src/libstat/stat_config.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index bca4cd954c..e307c276c9 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -193,13 +193,37 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base) void rspamd_stat_close (void) { - guint i; + struct rspamd_classifier *cl; + struct rspamd_statfile *st; + struct rspamd_stat_ctx *st_ctx; + guint i, j; + gint id; - g_assert (stat_ctx != NULL); + st_ctx = rspamd_stat_get_ctx (); + g_assert (st_ctx != NULL); - /* TODO: add cleanup routine */ + for (i = 0; i < st_ctx->classifiers->len; i ++) { + cl = g_ptr_array_index (st_ctx->classifiers, i); + for (j = 0; j < cl->statfiles_ids->len; j ++) { + id = g_array_index (cl->statfiles_ids, gint, j); + st = g_ptr_array_index (st_ctx->statfiles, id); + st->backend->close (st->bkcf); + + g_slice_free1 (sizeof (*st), st); + } + + g_array_free (cl->statfiles_ids, TRUE); + g_slice_free1 (sizeof (*cl), cl); + } + + g_ptr_array_free (st_ctx->statfiles, TRUE); + g_ptr_array_free (st_ctx->classifiers, TRUE); REF_RELEASE (stat_ctx->cfg); + g_slice_free1 (sizeof (*st_ctx), st_ctx); + + /* Set global var to NULL */ + stat_ctx = NULL; } struct rspamd_stat_ctx * -- 2.47.3