From 99c0a7ad72fbe9ca3ffe7905eebafd8bb418bc5a Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 19 May 2015 15:14:49 +0200 Subject: [PATCH] multi-detect: improve memory handling of setup code --- src/detect-engine.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/detect-engine.c b/src/detect-engine.c index d97e6eaa81..02b1f70beb 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -2681,6 +2681,8 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv) uint32_t map_cnt = 0; int max_tenant_id = 0; DetectEngineCtx *list = master->list; + HashTable *mt_det_ctxs_hash = NULL; + DetectEngineThreadCtx *det_ctx = NULL; if (master->tenant_selector == TENANT_SELECTOR_UNKNOWN) { SCLogError(SC_ERR_MT_NO_SELECTOR, "no tenant selector set: " @@ -2697,8 +2699,10 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv) tcnt++; } - HashTable *mt_det_ctxs_hash = HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree); - BUG_ON(mt_det_ctxs_hash == NULL); + mt_det_ctxs_hash = HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree); + if (mt_det_ctxs_hash == NULL) { + goto error; + } if (max_tenant_id == 0) { SCLogInfo("no tenants left, or none registered yet"); @@ -2744,11 +2748,12 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv) } } - DetectEngineThreadCtx *det_ctx = SCCalloc(1, sizeof(DetectEngineThreadCtx)); + det_ctx = SCCalloc(1, sizeof(DetectEngineThreadCtx)); if (det_ctx == NULL) { goto error; } det_ctx->mt_det_ctxs_hash = mt_det_ctxs_hash; + mt_det_ctxs_hash = NULL; /* first register the counter. In delayed detect mode we exit right after if the * rules haven't been loaded yet. */ @@ -2788,6 +2793,11 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv) return det_ctx; error: + if (map_array != NULL) + SCFree(map_array); + if (mt_det_ctxs_hash != NULL) + HashTableFree(mt_det_ctxs_hash); + return NULL; } -- 2.47.2