]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
multi-detect: improve memory handling of setup code
authorVictor Julien <victor@inliniac.net>
Tue, 19 May 2015 13:14:49 +0000 (15:14 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 23 Jul 2015 17:36:16 +0000 (19:36 +0200)
src/detect-engine.c

index d97e6eaa81f51a74591464948643cefab4d6d597..02b1f70beb2003c5c7444381eb378760054a321f 100644 (file)
@@ -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;
 }