From: Anoop Saldanha Date: Tue, 3 Jul 2012 07:23:47 +0000 (+0530) Subject: ac-bs and ac-gfbs mem cleanup X-Git-Tag: suricata-1.3~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0b29fb85afa36ee69c447fe7eb5a321a881b45a;p=thirdparty%2Fsuricata.git ac-bs and ac-gfbs mem cleanup --- diff --git a/src/util-mpm-ac-bs.c b/src/util-mpm-ac-bs.c index 60608ab9fb..a9c00d1bc3 100644 --- a/src/util-mpm-ac-bs.c +++ b/src/util-mpm-ac-bs.c @@ -1383,6 +1383,35 @@ void SCACBSDestroyCtx(MpmCtx *mpm_ctx) sizeof(SC_AC_BS_STATE_TYPE_U32) * 256); } + if (ctx->output_table != NULL) { + uint32_t state_count; + for (state_count = 0; state_count < ctx->state_count; state_count++) { + if (ctx->output_table[state_count].pids != NULL) { + SCFree(ctx->output_table[state_count].pids); + } + } + SCFree(ctx->output_table); + } + + if (ctx->pid_pat_list != NULL) { + int i; + for (i = 0; i < (ctx->max_pat_id + 1); i++) { + if (ctx->pid_pat_list[i].cs != NULL) + SCFree(ctx->pid_pat_list[i].cs); + } + SCFree(ctx->pid_pat_list); + } + + if (ctx->state_table_mod != NULL) { + SCFree(ctx->state_table_mod); + ctx->state_table_mod = NULL; + } + + if (ctx->state_table_mod_pointers != NULL) { + SCFree(ctx->state_table_mod_pointers); + ctx->state_table_mod_pointers = NULL; + } + SCFree(mpm_ctx->ctx); mpm_ctx->memory_cnt--; mpm_ctx->memory_size -= sizeof(SCACBSCtx); diff --git a/src/util-mpm-ac-gfbs.c b/src/util-mpm-ac-gfbs.c index 08fd21ffd3..abfa86d5c6 100644 --- a/src/util-mpm-ac-gfbs.c +++ b/src/util-mpm-ac-gfbs.c @@ -1260,6 +1260,25 @@ void SCACGfbsDestroyCtx(MpmCtx *mpm_ctx) mpm_ctx->memory_size -= ctx->state_count * sizeof(uint8_t *); } + if (ctx->output_table != NULL) { + int32_t state_count; + for (state_count = 0; state_count < ctx->state_count; state_count++) { + if (ctx->output_table[state_count].pids != NULL) { + SCFree(ctx->output_table[state_count].pids); + } + } + SCFree(ctx->output_table); + } + + if (ctx->pid_pat_list != NULL) { + int i; + for (i = 0; i < (ctx->max_pat_id + 1); i++) { + if (ctx->pid_pat_list[i].cs != NULL) + SCFree(ctx->pid_pat_list[i].cs); + } + SCFree(ctx->pid_pat_list); + } + SCFree(mpm_ctx->ctx); mpm_ctx->memory_cnt--; mpm_ctx->memory_size -= sizeof(SCACGfbsCtx); diff --git a/src/util-mpm.c b/src/util-mpm.c index 785915120e..c1510123ec 100644 --- a/src/util-mpm.c +++ b/src/util-mpm.c @@ -230,7 +230,8 @@ void MpmFactoryReClaimMpmCtx(DetectEngineCtx *de_ctx, MpmCtx *mpm_ctx) return; if (!MpmFactoryIsMpmCtxAvailable(de_ctx, mpm_ctx)) { - mpm_table[mpm_ctx->mpm_type].DestroyCtx(mpm_ctx); + if (mpm_ctx->mpm_type != MPM_NOTSET) + mpm_table[mpm_ctx->mpm_type].DestroyCtx(mpm_ctx); SCFree(mpm_ctx); } @@ -248,11 +249,13 @@ void MpmFactoryDeRegisterAllMpmCtxProfiles(DetectEngineCtx *de_ctx) if (items[i].name != NULL) SCFree(items[i].name); if (items[i].mpm_ctx_ts != NULL) { - mpm_table[items[i].mpm_ctx_ts->mpm_type].DestroyCtx(items[i].mpm_ctx_ts); + if (items[i].mpm_ctx_ts->mpm_type != MPM_NOTSET) + mpm_table[items[i].mpm_ctx_ts->mpm_type].DestroyCtx(items[i].mpm_ctx_ts); SCFree(items[i].mpm_ctx_ts); } if (items[i].mpm_ctx_tc != NULL) { - mpm_table[items[i].mpm_ctx_tc->mpm_type].DestroyCtx(items[i].mpm_ctx_tc); + if (items[i].mpm_ctx_tc->mpm_type != MPM_NOTSET) + mpm_table[items[i].mpm_ctx_tc->mpm_type].DestroyCtx(items[i].mpm_ctx_tc); SCFree(items[i].mpm_ctx_tc); } }