]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unittests: clean up packet clear logic
authorVictor Julien <vjulien@oisf.net>
Wed, 23 Feb 2022 12:41:42 +0000 (13:41 +0100)
committerShivani Bhardwaj <shivanib134@gmail.com>
Tue, 8 Mar 2022 15:03:50 +0000 (20:33 +0530)
(cherry picked from commit 0437ca61ff81e3597a00e1e11311f4e9dc7182a5)

src/app-layer.c
src/detect-hostbits.c

index 9df5ea15372d18ea73778cb2d0d155eb73a79f62..47c907ea4b637a1ca09fe75696ce48ef907b42aa 100644 (file)
@@ -1015,7 +1015,7 @@ void AppLayerDeSetupCounters()
 #include "util-unittest.h"
 
 #define TEST_START                                                                                 \
-    Packet *p = SCMalloc(SIZE_OF_PACKET);                                                          \
+    Packet *p = PacketGetFromAlloc();                                                              \
     FAIL_IF_NULL(p);                                                                               \
     Flow f;                                                                                        \
     ThreadVars tv;                                                                                 \
@@ -1101,8 +1101,7 @@ void AppLayerDeSetupCounters()
     StreamTcpSessionClear(p->flow->protoctx);                                                      \
     StreamTcpThreadDeinit(&tv, (void *)stt);                                                       \
     StreamTcpFreeConfig(TRUE);                                                                     \
-    PACKET_DESTRUCTOR(p);                                                                          \
-    SCFree(p);                                                                                     \
+    PacketFree(p);                                                                                 \
     FLOW_DESTROY(&f);                                                                              \
     StatsThreadCleanup(&tv);
 
index 35574150bbf1b2cc8c6ce1c45743fb08fbd57956..9e33138dd17505e533e784b1bb79fa4abb50406c 100644 (file)
@@ -555,7 +555,7 @@ static int HostBitsTestSig01(void)
                     "Host: one.example.org\r\n"
                     "\r\n";
     uint16_t buflen = strlen((char *)buf);
-    Packet *p = SCMalloc(SIZE_OF_PACKET);
+    Packet *p = PacketGetFromAlloc();
     FAIL_IF_NULL(p);
     Signature *s = NULL;
     ThreadVars th_v;
@@ -587,9 +587,8 @@ static int HostBitsTestSig01(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
     HostBitsTestShutdown();
-
-    SCFree(p);
     PASS;
 }
 
@@ -736,7 +735,7 @@ static int HostBitsTestSig04(void)
                     "Host: one.example.org\r\n"
                     "\r\n";
     uint16_t buflen = strlen((char *)buf);
-    Packet *p = SCMalloc(SIZE_OF_PACKET);
+    Packet *p = PacketGetFromAlloc();
     if (unlikely(p == NULL))
         return 0;
     Signature *s = NULL;
@@ -773,9 +772,9 @@ static int HostBitsTestSig04(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
     HostBitsTestShutdown();
 
-    SCFree(p);
     PASS;
 }
 
@@ -793,9 +792,7 @@ static int HostBitsTestSig05(void)
                     "Host: one.example.org\r\n"
                     "\r\n";
     uint16_t buflen = strlen((char *)buf);
-    Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-        return 0;
+    Packet *p = PacketGetFromAlloc();
     Signature *s = NULL;
     ThreadVars th_v;
     DetectEngineThreadCtx *det_ctx = NULL;
@@ -833,10 +830,10 @@ static int HostBitsTestSig05(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
 
     HostBitsTestShutdown();
 
-    SCFree(p);
     PASS;
 }
 
@@ -1065,9 +1062,7 @@ static int HostBitsTestSig07(void)
                     "Host: one.example.org\r\n"
                     "\r\n";
     uint16_t buflen = strlen((char *)buf);
-    Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-        return 0;
+    Packet *p = PacketGetFromAlloc();
     Signature *s = NULL;
     ThreadVars th_v;
     DetectEngineThreadCtx *det_ctx = NULL;
@@ -1125,9 +1120,8 @@ static int HostBitsTestSig07(void)
     DetectEngineCtxFree(de_ctx);
 
     FLOW_DESTROY(&f);
-
+    PacketFree(p);
     HostBitsTestShutdown();
-    SCFree(p);
     PASS;
 }
 
@@ -1144,9 +1138,7 @@ static int HostBitsTestSig08(void)
                     "Host: one.example.org\r\n"
                     "\r\n";
     uint16_t buflen = strlen((char *)buf);
-    Packet *p = SCMalloc(SIZE_OF_PACKET);
-    if (unlikely(p == NULL))
-        return 0;
+    Packet *p = PacketGetFromAlloc();
     Signature *s = NULL;
     ThreadVars th_v;
     DetectEngineThreadCtx *det_ctx = NULL;
@@ -1221,10 +1213,9 @@ static int HostBitsTestSig08(void)
     DetectEngineCtxFree(de_ctx);
 
     FLOW_DESTROY(&f);
-
+    PacketFree(p);
     HostBitsTestShutdown();
 
-    SCFree(p);
     PASS;
 }
 
@@ -1247,4 +1238,4 @@ void HostBitsRegisterTests(void)
     UtRegisterTest("HostBitsTestSig07", HostBitsTestSig07);
     UtRegisterTest("HostBitsTestSig08", HostBitsTestSig08);
 }
-#endif /* UNITTESTS */
\ No newline at end of file
+#endif /* UNITTESTS */