]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
counters: clean up global context
authorVictor Julien <victor@inliniac.net>
Wed, 27 May 2015 07:28:24 +0000 (09:28 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 27 May 2015 12:15:35 +0000 (14:15 +0200)
src/counters.c

index 997ad01ca3b276f719b89fee2c3294ba17827acd..a50160e2b88d122d7fbd9c0caf454f704fe0c112 100644 (file)
@@ -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)