From: Victor Julien Date: Wed, 27 May 2015 09:23:19 +0000 (+0200) Subject: counters: make threads cleanup all memory X-Git-Tag: suricata-3.0RC1~347 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e48153c6b0fb95e6cab8ff652a8211d54418c326;p=thirdparty%2Fsuricata.git counters: make threads cleanup all memory --- diff --git a/src/counters.c b/src/counters.c index a50160e2b8..08f6329a29 100644 --- a/src/counters.c +++ b/src/counters.c @@ -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 diff --git a/src/counters.h b/src/counters.h index 01e65e3b72..229e6c9f24 100644 --- a/src/counters.h +++ b/src/counters.h @@ -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); \ diff --git a/src/tm-threads.c b/src/tm-threads.c index a922a82253..f0f8a3cf0a 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -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) {