]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
counters: make threads cleanup all memory
authorVictor Julien <victor@inliniac.net>
Wed, 27 May 2015 09:23:19 +0000 (11:23 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 27 May 2015 12:21:18 +0000 (14:21 +0200)
src/counters.c
src/counters.h
src/tm-threads.c

index a50160e2b88d122d7fbd9c0caf454f704fe0c112..08f6329a29106769d8828ca45ff8b04bd1fb090f 100644 (file)
@@ -104,17 +104,19 @@ static StatsTable stats_table = { NULL, NULL, 0, 0, 0, {0 , 0}};
 
 static uint16_t counters_global_id = 0;
 
-void StatsPublicThreadContextInit(StatsPublicThreadContext *t)
+static void StatsPublicThreadContextInit(StatsPublicThreadContext *t)
 {
     SCMutexInit(&t->m, NULL);
 }
 
-void StatsPublicThreadContextCleanup(StatsPublicThreadContext *t)
+static void StatsPublicThreadContextCleanup(StatsPublicThreadContext *t)
 {
     SCMutexLock(&t->m);
     StatsReleaseCounters(t->head);
+    t->head = NULL;
+    t->perf_flag = 0;
+    t->curr_id = 0;
     SCMutexUnlock(&t->m);
-
     SCMutexDestroy(&t->m);
 }
 
@@ -1026,13 +1028,7 @@ static int StatsThreadRegister(const char *thread_name, StatsPublicThreadContext
     memset(temp, 0, sizeof(StatsThreadStore));
 
     temp->ctx = pctx;
-
-    temp->name = SCStrdup(thread_name);
-    if (unlikely(temp->name == NULL)) {
-        SCFree(temp);
-        SCMutexUnlock(&stats_ctx->sts_lock);
-        return 0;
-    }
+    temp->name = thread_name;
 
     temp->next = stats_ctx->sts;
     stats_ctx->sts = temp;
@@ -1213,6 +1209,7 @@ void StatsReleasePrivateThreadContext(StatsPrivateThreadContext *pca)
         if (pca->head != NULL) {
             SCFree(pca->head);
             pca->head = NULL;
+            pca->size = 0;
         }
         pca->initialized = 0;
     }
@@ -1220,6 +1217,12 @@ void StatsReleasePrivateThreadContext(StatsPrivateThreadContext *pca)
     return;
 }
 
+void StatsThreadCleanup(ThreadVars *tv)
+{
+    StatsPublicThreadContextCleanup(&tv->perf_public_ctx);
+    StatsReleasePrivateThreadContext(&tv->perf_private_ctx);
+}
+
 /*----------------------------------Unit_Tests--------------------------------*/
 
 #ifdef UNITTESTS
index 01e65e3b72f281502a40fe368ffa3f7082adfb2f..229e6c9f24c2ff87cedbbb09a3db15c6df76b6f9 100644 (file)
@@ -127,6 +127,7 @@ void StatsIncr(struct ThreadVars_ *, uint16_t);
 int StatsUpdateCounterArray(StatsPrivateThreadContext *, StatsPublicThreadContext *);
 uint64_t StatsGetLocalCounterValue(struct ThreadVars_ *, uint16_t);
 int StatsSetupPrivate(struct ThreadVars_ *);
+void StatsThreadCleanup(struct ThreadVars_ *);
 
 #define StatsSyncCounters(tv) \
     StatsUpdateCounterArray(&(tv)->perf_private_ctx, &(tv)->perf_public_ctx);  \
index a922a82253f2eabf7e9ce785f32847687e05e797..f0f8a3cf0a925252cb70a7da98b0c6bd471cad7c 100644 (file)
@@ -1647,7 +1647,7 @@ void TmThreadFree(ThreadVars *tv)
 
     SCLogDebug("Freeing thread '%s'.", tv->name);
 
-    SCMutexDestroy(&tv->perf_public_ctx.m);
+    StatsThreadCleanup(tv);
 
     s = (TmSlot *)tv->tm_slots;
     while (s) {