]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: avoid potential use-after-free in error path
authorVictor Julien <victor@inliniac.net>
Mon, 30 Jul 2018 15:04:57 +0000 (17:04 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 2 Aug 2018 09:21:32 +0000 (11:21 +0200)
src/detect-engine.c

index 9fe7de6416493067334a7a745b608a913a6d6001..c5fa7e5e3f880402c8fcd62320041b7aa62ebb29 100644 (file)
@@ -2322,14 +2322,16 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
     det_ctx->counter_match_list = StatsRegisterAvgCounter("detect.match_list", tv);
 #endif
 
-    /* pass thread data back to caller */
-    *data = (void *)det_ctx;
-
     if (DetectEngineMultiTenantEnabled()) {
-        if (DetectEngineThreadCtxInitForMT(tv, det_ctx) != TM_ECODE_OK)
+        if (DetectEngineThreadCtxInitForMT(tv, det_ctx) != TM_ECODE_OK) {
+            DetectEngineThreadCtxDeinit(tv, det_ctx);
             return TM_ECODE_FAILED;
+        }
     }
 
+    /* pass thread data back to caller */
+    *data = (void *)det_ctx;
+
     return TM_ECODE_OK;
 }