From: Victor Julien Date: Wed, 27 May 2015 07:28:24 +0000 (+0200) Subject: counters: clean up global context X-Git-Tag: suricata-3.0RC1~348 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=81548ae3e804347f1c39b6f7e56738906ac53f64;p=thirdparty%2Fsuricata.git counters: clean up global context --- diff --git a/src/counters.c b/src/counters.c index 997ad01ca3..a50160e2b8 100644 --- a/src/counters.c +++ b/src/counters.c @@ -96,6 +96,7 @@ static char stats_enabled = TRUE; static int StatsOutput(ThreadVars *tv); static int StatsThreadRegister(const char *thread_name, StatsPublicThreadContext *); +void StatsReleaseCounters(StatsCounter *head); /** stats table is filled each interval and passed to the * loggers. Initialized at first use. */ @@ -103,6 +104,20 @@ static StatsTable stats_table = { NULL, NULL, 0, 0, 0, {0 , 0}}; static uint16_t counters_global_id = 0; +void StatsPublicThreadContextInit(StatsPublicThreadContext *t) +{ + SCMutexInit(&t->m, NULL); +} + +void StatsPublicThreadContextCleanup(StatsPublicThreadContext *t) +{ + SCMutexLock(&t->m); + StatsReleaseCounters(t->head); + SCMutexUnlock(&t->m); + + SCMutexDestroy(&t->m); +} + /** * \brief Adds a value of type uint64_t to the local counter. * @@ -254,14 +269,26 @@ static void StatsReleaseCtx() sts = temp; } + if (stats_ctx->counters_id_hash != NULL) { + HashTableFree(stats_ctx->counters_id_hash); + stats_ctx->counters_id_hash = NULL; + } + + StatsPublicThreadContextCleanup(&stats_ctx->global_counter_ctx); SCFree(stats_ctx); stats_ctx = NULL; /* free stats table */ + if (stats_table.tstats != NULL) { + SCFree(stats_table.tstats); + stats_table.tstats = NULL; + } + if (stats_table.stats != NULL) { SCFree(stats_table.stats); - memset(&stats_table, 0, sizeof(stats_table)); + stats_table.stats = NULL; } + memset(&stats_table, 0, sizeof(stats_table)); return; } @@ -750,6 +777,8 @@ void StatsInit(void) exit(EXIT_FAILURE); } memset(stats_ctx, 0, sizeof(StatsGlobalContext)); + + StatsPublicThreadContextInit(&stats_ctx->global_counter_ctx); } void StatsSetupPostConfig(void)