multi-detect: improve memory handling of setup code

pull/1608/head
Victor Julien 10 years ago
parent b7b27684c2
commit 99c0a7ad72

@ -2681,6 +2681,8 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv)
uint32_t map_cnt = 0; uint32_t map_cnt = 0;
int max_tenant_id = 0; int max_tenant_id = 0;
DetectEngineCtx *list = master->list; DetectEngineCtx *list = master->list;
HashTable *mt_det_ctxs_hash = NULL;
DetectEngineThreadCtx *det_ctx = NULL;
if (master->tenant_selector == TENANT_SELECTOR_UNKNOWN) { if (master->tenant_selector == TENANT_SELECTOR_UNKNOWN) {
SCLogError(SC_ERR_MT_NO_SELECTOR, "no tenant selector set: " SCLogError(SC_ERR_MT_NO_SELECTOR, "no tenant selector set: "
@ -2697,8 +2699,10 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv)
tcnt++; tcnt++;
} }
HashTable *mt_det_ctxs_hash = HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree); mt_det_ctxs_hash = HashTableInit(tcnt * 2, TenantIdHash, TenantIdCompare, TenantIdFree);
BUG_ON(mt_det_ctxs_hash == NULL); if (mt_det_ctxs_hash == NULL) {
goto error;
}
if (max_tenant_id == 0) { if (max_tenant_id == 0) {
SCLogInfo("no tenants left, or none registered yet"); 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) { if (det_ctx == NULL) {
goto error; goto error;
} }
det_ctx->mt_det_ctxs_hash = mt_det_ctxs_hash; 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 /* first register the counter. In delayed detect mode we exit right after if the
* rules haven't been loaded yet. */ * rules haven't been loaded yet. */
@ -2788,6 +2793,11 @@ static DetectEngineThreadCtx *DetectEngineThreadCtxInitForMT(ThreadVars *tv)
return det_ctx; return det_ctx;
error: error:
if (map_array != NULL)
SCFree(map_array);
if (mt_det_ctxs_hash != NULL)
HashTableFree(mt_det_ctxs_hash);
return NULL; return NULL;
} }

Loading…
Cancel
Save