]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unittests: clean up packet clear logic
authorJeff Lucovsky <jeff@lucovsky.org>
Sun, 27 Feb 2022 18:12:10 +0000 (13:12 -0500)
committerJeff Lucovsky <jeff@lucovsky.org>
Fri, 11 Mar 2022 14:03:32 +0000 (09:03 -0500)
Substitute for cherry-picking 629acb8141e608b3d34eee576a7e121c7555d2c3

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

index 5a4f5dc94863d34400c4f2af69af5526b68ecd89..6221bd3cd5644834b8f6028a5948676326780027 100644 (file)
@@ -989,7 +989,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;\
@@ -1075,8 +1075,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 86c1218b5d7cf49caa7fb228515b7fc78c8ebbaa..23eaf451552f5e33f3847a5da45d5114a5524cab 100644 (file)
@@ -553,7 +553,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;
@@ -585,9 +585,9 @@ static int HostBitsTestSig01(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
     HostBitsTestShutdown();
 
-    SCFree(p);
     PASS;
 }
 
@@ -734,9 +734,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);
-    if (unlikely(p == NULL))
-        return 0;
+    Packet *p = PacketGetFromAlloc();
     Signature *s = NULL;
     ThreadVars th_v;
     DetectEngineThreadCtx *det_ctx = NULL;
@@ -771,9 +769,9 @@ static int HostBitsTestSig04(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
     HostBitsTestShutdown();
 
-    SCFree(p);
     PASS;
 }
 
@@ -791,9 +789,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;
@@ -831,10 +827,10 @@ static int HostBitsTestSig05(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
 
     HostBitsTestShutdown();
 
-    SCFree(p);
     PASS;
 }
 
@@ -957,9 +953,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;
@@ -1022,11 +1016,11 @@ static int HostBitsTestSig07(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
 
     if(gv) GenericVarFree(gv);
     FLOW_DESTROY(&f);
 
-    SCFree(p);
     return result;
 end:
 
@@ -1043,11 +1037,12 @@ end:
         DetectEngineCtxFree(de_ctx);
     }
 
+    PacketFree(p);
+
     if(gv) GenericVarFree(gv);
     FLOW_DESTROY(&f);
 
-    SCFree(p);
-    return result;}
+    return result;
 #endif
 
 /**
@@ -1063,9 +1058,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;
@@ -1121,11 +1114,11 @@ static int HostBitsTestSig07(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
 
     FLOW_DESTROY(&f);
 
     HostBitsTestShutdown();
-    SCFree(p);
     PASS;
 }
 
@@ -1142,9 +1135,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;
@@ -1217,12 +1208,12 @@ static int HostBitsTestSig08(void)
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+    PacketFree(p);
 
     FLOW_DESTROY(&f);
 
     HostBitsTestShutdown();
 
-    SCFree(p);
     PASS;
 }
 #endif /* UNITTESTS */