]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unittest: recycle packet before exit
authorEric Leblond <eric@regit.org>
Tue, 27 Aug 2013 06:52:57 +0000 (08:52 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 28 Aug 2013 18:22:13 +0000 (20:22 +0200)
To avoid an issue with flow validation, we need to recycle the packet
before cleaning the flow.

16 files changed:
src/alert-unified2-alert.c
src/decode-icmpv6.c
src/decode-ipv4.c
src/decode-ipv6.c
src/decode-raw.c
src/decode-tcp.c
src/decode-vlan.c
src/detect-content.c
src/detect-csum.c
src/detect-dsize.c
src/detect-engine-port.c
src/detect-flowint.c
src/detect-fragbits.c
src/detect-parse.c
src/detect-replace.c
src/detect.c

index bb6ed925a57564d95bcd11acb404b3e0b7f16a69..73c4a087393aa232c73c5988199b695c04012cc2 100644 (file)
 #include "alert-unified2-alert.h"
 #include "decode-ipv4.h"
 
+#include "host.h"
+#include "util-profiling.h"
+#include "decode.h"
+
 #include "util-error.h"
 #include "util-debug.h"
 #include "util-time.h"
@@ -1162,39 +1166,40 @@ static int Unified2Test01 (void)   {
 
     DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq);
 
-    FlowShutdown();
 
     oc = Unified2AlertInitCtx(NULL);
     if (oc == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     lf = (LogFileCtx *)oc->data;
     if(lf == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadInit(&tv, oc, &data);
     if(ret == TM_ECODE_FAILED) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2Alert(&tv, p, data, &pq, NULL);
     if(ret == TM_ECODE_FAILED) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadDeinit(&tv, data);
     if(ret == -1) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
 
     Unified2AlertDeInitCtx(oc);
 
-    PACKET_CLEANUP(p);
+    PACKET_RECYCLE(p);
     SCFree(p);
+    FlowShutdown();
     return 1;
+
+end:
+    PACKET_RECYCLE(p);
+    SCFree(p);
+    FlowShutdown();
+    return 0;
 }
 
 /**
@@ -1248,39 +1253,39 @@ static int Unified2Test02 (void)   {
 
     DecodeEthernet(&tv, &dtv, p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq);
 
-    FlowShutdown();
-
     oc = Unified2AlertInitCtx(NULL);
     if (oc == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     lf = (LogFileCtx *)oc->data;
     if(lf == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadInit(&tv, oc, &data);
     if(ret == -1) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2Alert(&tv, p, data, &pq, NULL);
     if(ret == TM_ECODE_FAILED) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadDeinit(&tv, data);
     if(ret == -1) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
 
     Unified2AlertDeInitCtx(oc);
 
-    PACKET_CLEANUP(p);
+    PACKET_RECYCLE(p);
     SCFree(p);
+    FlowShutdown();
     return 1;
+
+end:
+    PACKET_RECYCLE(p);
+    SCFree(p);
+    FlowShutdown();
+    return 0;
 }
 
 
@@ -1319,6 +1324,7 @@ static int Unified2Test03 (void) {
         0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, 0x74,
         0x0d, 0x0a};
     Packet *p = PacketGetFromAlloc();
+    Packet *pkt;
     if (unlikely(p == NULL))
         return 0;
     int ret;
@@ -1340,45 +1346,52 @@ static int Unified2Test03 (void) {
 
     DecodeEthernet(&tv, &dtv, p, raw_gre, sizeof(raw_gre), &pq);
 
-    FlowShutdown();
-
     oc = Unified2AlertInitCtx(NULL);
     if (oc == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     lf = (LogFileCtx *)oc->data;
     if(lf == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadInit(&tv, oc, &data);
     if(ret == -1) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2Alert(&tv, p, data, &pq, NULL);
     if(ret == TM_ECODE_FAILED) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadDeinit(&tv, data);
     if(ret == -1) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
 
     Unified2AlertDeInitCtx(oc);
 
-    Packet *pkt = PacketDequeue(&pq);
+    pkt = PacketDequeue(&pq);
     while (pkt != NULL) {
+        PACKET_RECYCLE(pkt);
         SCFree(pkt);
         pkt = PacketDequeue(&pq);
     }
 
-    PACKET_CLEANUP(p);
+    PACKET_RECYCLE(p);
     SCFree(p);
+    FlowShutdown();
     return 1;
+
+end:
+    pkt = PacketDequeue(&pq);
+    while (pkt != NULL) {
+        PACKET_RECYCLE(pkt);
+        SCFree(pkt);
+        pkt = PacketDequeue(&pq);
+    }
+    PACKET_RECYCLE(p);
+    SCFree(p);
+    FlowShutdown();
+    return 0;
 }
 
 /**
@@ -1426,39 +1439,39 @@ static int Unified2Test04 (void)   {
 
     DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), &pq);
 
-    FlowShutdown();
-
     oc = Unified2AlertInitCtx(NULL);
     if (oc == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     lf = (LogFileCtx *)oc->data;
     if(lf == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadInit(&tv, oc, &data);
     if(ret == -1) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2Alert(&tv, p, data, &pq, NULL);
     if(ret == TM_ECODE_FAILED) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadDeinit(&tv, data);
     if(ret == -1) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
 
     Unified2AlertDeInitCtx(oc);
 
-    PACKET_CLEANUP(p);
+    PACKET_RECYCLE(p);
     SCFree(p);
+    FlowShutdown();
     return 1;
+
+end:
+    PACKET_RECYCLE(p);
+    SCFree(p);
+    FlowShutdown();
+    return 0;
 }
 
 /**
@@ -1510,41 +1523,41 @@ static int Unified2Test05 (void)   {
 
     DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq);
 
-    FlowShutdown();
-
     p->action = ACTION_DROP;
 
     oc = Unified2AlertInitCtx(NULL);
     if (oc == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     lf = (LogFileCtx *)oc->data;
     if(lf == NULL) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadInit(&tv, oc, &data);
     if(ret == -1) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2Alert(&tv, p, data, &pq, NULL);
     if(ret == TM_ECODE_FAILED) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
     ret = Unified2AlertThreadDeinit(&tv, data);
     if(ret == TM_ECODE_FAILED) {
-        SCFree(p);
-        return 0;
+        goto end;
     }
 
     Unified2AlertDeInitCtx(oc);
 
-    PACKET_CLEANUP(p);
+    PACKET_RECYCLE(p);
     SCFree(p);
+    FlowShutdown();
     return 1;
+
+end:
+    PACKET_RECYCLE(p);
+    SCFree(p);
+    FlowShutdown();
+    return 0;
 }
 
 /**
index 1a7866b97e33b4636035f725d4a6d5a89c650632..6a5c6e46d7de473d5eae6b87a81a18e0ed195669 100644 (file)
 #include "util-debug.h"
 #include "util-print.h"
 
+#include "pkt-var.h"
+#include "util-profiling.h"
+#include "host.h"
+
 
 /**
  * \brief Get variables and do some checks of the embedded IPV6 packet
@@ -387,7 +391,6 @@ static int ICMPV6ParamProbTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->icmpv6h == NULL) {
         SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@@ -416,6 +419,8 @@ static int ICMPV6ParamProbTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -459,7 +464,6 @@ static int ICMPV6PktTooBigTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->icmpv6h == NULL) {
         SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@@ -490,6 +494,8 @@ static int ICMPV6PktTooBigTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -534,7 +540,6 @@ static int ICMPV6TimeExceedTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->icmpv6h == NULL) {
         SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@@ -566,6 +571,8 @@ static int ICMPV6TimeExceedTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -610,7 +617,6 @@ static int ICMPV6DestUnreachTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->icmpv6h == NULL) {
         SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@@ -640,6 +646,8 @@ static int ICMPV6DestUnreachTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -673,7 +681,6 @@ static int ICMPV6EchoReqTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->icmpv6h == NULL) {
         SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@@ -692,6 +699,8 @@ static int ICMPV6EchoReqTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -726,7 +735,6 @@ static int ICMPV6EchoRepTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->icmpv6h == NULL) {
         SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@@ -746,6 +754,8 @@ static int ICMPV6EchoRepTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -786,7 +796,6 @@ static int ICMPV6ParamProbTest02(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->icmpv6h == NULL) {
         SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@@ -808,6 +817,8 @@ static int ICMPV6ParamProbTest02(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -847,7 +858,6 @@ static int ICMPV6PktTooBigTest02(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->icmpv6h == NULL) {
         SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@@ -863,6 +873,8 @@ static int ICMPV6PktTooBigTest02(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -899,7 +911,6 @@ static int ICMPV6TimeExceedTest02(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (!ENGINE_ISSET_EVENT(p, ICMPV6_PKT_TOO_SMALL)) {
         SCLogDebug("ICMPv6 Error: event packet too small not set");
@@ -909,6 +920,8 @@ static int ICMPV6TimeExceedTest02(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -948,7 +961,6 @@ static int ICMPV6DestUnreachTest02(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (!ENGINE_ISSET_EVENT(p, ICMPV6_IPV6_TRUNC_PKT)) {
         SCLogDebug("ICMPv6 Error: embedded ipv6 truncated packet event not set");
@@ -958,6 +970,8 @@ static int ICMPV6DestUnreachTest02(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -993,7 +1007,6 @@ static int ICMPV6EchoReqTest02(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
         SCLogDebug("ICMPv6 Error: Unknown code event not set");
@@ -1003,6 +1016,8 @@ static int ICMPV6EchoReqTest02(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -1038,7 +1053,6 @@ static int ICMPV6EchoRepTest02(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
         SCLogDebug("ICMPv6 Error: Unknown code event not set");
@@ -1048,6 +1062,8 @@ static int ICMPV6EchoRepTest02(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -1086,7 +1102,6 @@ static int ICMPV6PayloadTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
-    FlowShutdown();
 
     if (p->payload == NULL) {
         printf("payload == NULL, expected non-NULL: ");
@@ -1100,6 +1115,8 @@ static int ICMPV6PayloadTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
index 76bed8e863e906e4490b0081b1750e119a2b875e..5922db0b0dc97e5cb73c63b0d183955179f14f0b 100644 (file)
@@ -1535,13 +1535,13 @@ int DecodeIPV4DefragTest01(void)
             goto end;
     }
 
-    PACKET_CLEANUP(p);
+    PACKET_RECYCLE(tp);
     SCFree(tp);
 
 end:
     DefragDestroy();
+    PACKET_RECYCLE(p);
     FlowShutdown();
-    PACKET_CLEANUP(p);
     SCFree(p);
     return result;
 }
@@ -1667,13 +1667,13 @@ int DecodeIPV4DefragTest02(void)
     }
 
     result = 1;
-    PACKET_CLEANUP(p);
+    PACKET_RECYCLE(tp);
     SCFree(tp);
 
 end:
     DefragDestroy();
+    PACKET_RECYCLE(p);
     FlowShutdown();
-    PACKET_CLEANUP(p);
     SCFree(p);
     return result;
 }
@@ -1826,13 +1826,13 @@ int DecodeIPV4DefragTest03(void)
             goto end;
     }
 
-    PACKET_CLEANUP(p);
+    PACKET_RECYCLE(tp);
     SCFree(tp);
 
 end:
     DefragDestroy();
+    PACKET_RECYCLE(p);
     FlowShutdown();
-    PACKET_CLEANUP(p);
     SCFree(p);
     return result;
 }
index 8059a3df4c4fc1cd6dc0e08832050198d19086a8..971b55cf3db7e7eaef64b9aea7478e2fa834c35b 100644 (file)
@@ -41,6 +41,8 @@
 #include "util-debug.h"
 #include "util-print.h"
 #include "util-unittest.h"
+#include "util-profiling.h"
+#include "host.h"
 
 #define IPV6_EXTHDRS     ip6eh.ip6_exthdrs
 #define IPV6_EH_CNT      ip6eh.ip6_exthdrs_cnt
@@ -738,6 +740,7 @@ static int DecodeIPV6FragTest01 (void)   {
         0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
         0x20, 0x20, 0x20, 0x20,
     };
+    Packet *pkt;
     Packet *p1 = PacketGetFromAlloc();
     if (unlikely(p1 == NULL))
         return 0;
@@ -782,10 +785,16 @@ static int DecodeIPV6FragTest01 (void)   {
 
     result = 1;
 end:
-    PACKET_CLEANUP(p1);
-    PACKET_CLEANUP(p2);
+    PACKET_RECYCLE(p1);
+    PACKET_RECYCLE(p2);
     SCFree(p1);
     SCFree(p2);
+    pkt = PacketDequeue(&pq);
+    while (pkt != NULL) {
+        PACKET_RECYCLE(pkt);
+        SCFree(pkt);
+        pkt = PacketDequeue(&pq);
+    }
     DefragDestroy();
     FlowShutdown();
     return result;
@@ -838,7 +847,7 @@ static int DecodeIPV6RouteTest01 (void)   {
 
     result = 1;
 end:
-    PACKET_CLEANUP(p1);
+    PACKET_RECYCLE(p1);
     SCFree(p1);
     FlowShutdown();
     return result;
index d5910ce4d7c3977e32d25558a69a3f79011bd5e4..16b8687221ba4d81c8a4e8e5b413c4cd8998f156 100644 (file)
 #include "util-unittest.h"
 #include "util-debug.h"
 
+#include "pkt-var.h"
+#include "util-profiling.h"
+#include "host.h"
+
+
 void DecodeRaw(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
 {
     SCPerfCounterIncr(dtv->counter_raw, tv->sc_perf_pca);
@@ -107,6 +112,7 @@ static int DecodeRawTest01 (void)   {
         return 1;
     }
 
+    PACKET_RECYCLE(p);
     FlowShutdown();
     SCFree(p);
     return 0;
@@ -144,13 +150,16 @@ static int DecodeRawTest02 (void)   {
     FlowInitConfig(FLOW_QUIET);
 
     DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p), NULL);
-    FlowShutdown();
     if (p->ip4h == NULL) {
         printf("expected a valid ipv4 header but it was NULL: ");
+        PACKET_RECYCLE(p);
+        FlowShutdown();
         SCFree(p);
         return 1;
     }
 
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return 0;
 }
@@ -195,6 +204,7 @@ static int DecodeRawTest03 (void)   {
     } else {
         printf("expected IPRAW_INVALID_IPV to be set but it wasn't: ");
     }
+    PACKET_RECYCLE(p);
     FlowShutdown();
     SCFree(p);
     return 1;
index a2e38855dc20d37482a1b207ae2ca00aea08ca51..e9a83afe1d50c74650e92b764fd0696e4cbc0e07 100644 (file)
@@ -38,6 +38,9 @@
 #include "util-debug.h"
 #include "util-optimize.h"
 #include "flow.h"
+#include "util-profiling.h"
+#include "pkt-var.h"
+#include "host.h"
 
 static int DecodeTCPOptions(Packet *p, uint8_t *pkt, uint16_t len)
 {
@@ -319,7 +322,6 @@ static int TCPGetWscaleTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
-    FlowShutdown();
 
     if (p->tcph == NULL) {
         printf("tcp packet decode failed: ");
@@ -334,6 +336,8 @@ static int TCPGetWscaleTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -364,7 +368,6 @@ static int TCPGetWscaleTest02(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
-    FlowShutdown();
 
     if (p->tcph == NULL) {
         printf("tcp packet decode failed: ");
@@ -379,6 +382,8 @@ static int TCPGetWscaleTest02(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -408,7 +413,6 @@ static int TCPGetWscaleTest03(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
-    FlowShutdown();
 
     if (p->tcph == NULL) {
         printf("tcp packet decode failed: ");
@@ -423,6 +427,8 @@ static int TCPGetWscaleTest03(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
@@ -456,7 +462,6 @@ static int TCPGetSackTest01(void)
 
     FlowInitConfig(FLOW_QUIET);
     DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
-    FlowShutdown();
 
     if (p->tcph == NULL) {
         printf("tcp packet decode failed: ");
@@ -487,6 +492,8 @@ static int TCPGetSackTest01(void)
 
     retval = 1;
 end:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return retval;
 }
index 11dab31113fa4f124a5aa61dd04964ebb786e485..ccf61e723a2c57b462ec548f791475938a4f5779 100644 (file)
 #include "util-unittest.h"
 #include "util-debug.h"
 
+#include "pkt-var.h"
+#include "util-profiling.h"
+#include "host.h"
+
 /**
  * \internal
  * \brief this function is used to decode IEEE802.1q packets
@@ -215,25 +219,29 @@ static int DecodeVLANtest03 (void)   {
 
     DecodeVLAN(&tv, &dtv, p, raw_vlan, sizeof(raw_vlan), NULL);
 
-    FlowShutdown();
 
     if(p->vlanh == NULL) {
-        SCFree(p);
-        return 0;
+        goto error;
     }
 
     if(ENGINE_ISSET_EVENT(p,VLAN_HEADER_TOO_SMALL))  {
-        SCFree(p);
-        return 0;
+        goto error;
     }
 
     if(ENGINE_ISSET_EVENT(p,VLAN_UNKNOWN_TYPE))  {
-        SCFree(p);
-        return 0;
+        goto error;
     }
 
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return 1;
+
+error:
+    PACKET_RECYCLE(p);
+    FlowShutdown();
+    SCFree(p);
+    return 0;
 }
 #endif /* UNITTESTS */
 
index 0a885cdbab5e9db7a5eb2ff200a893f149796703..e2d1a95dec7e3af5899d495a636e695b75855eed 100644 (file)
@@ -44,6 +44,9 @@
 #include "util-spm-bm.h"
 #include "threads.h"
 #include "util-unittest-helper.h"
+#include "pkt-var.h"
+#include "host.h"
+#include "util-profiling.h"
 
 int DetectContentMatch (ThreadVars *, DetectEngineThreadCtx *, Packet *, Signature *, SigMatch *);
 int DetectContentSetup(DetectEngineCtx *, Signature *, char *);
@@ -682,6 +685,7 @@ end:
             DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
         DetectEngineCtxFree(de_ctx);
     }
+    PACKET_RECYCLE(p);
     FlowShutdown();
 
     SCFree(p);
index 776cd656f800c6ba59badd8e23b3e0f4ab4a051c..c30a6dbd73499fef272352cceff87a0d3487f7ac 100644 (file)
 #include "util-unittest.h"
 #include "util-debug.h"
 
+#include "pkt-var.h"
+#include "host.h"
+#include "util-profiling.h"
+
 /* prototypes for the "ipv4-csum" rule keyword */
 int DetectIPV4CsumMatch(ThreadVars *, DetectEngineThreadCtx *, Packet *,
                         Signature *, SigMatch *);
@@ -1559,6 +1563,7 @@ int DetectCsumICMPV6Test01(void)
     }
 
     StreamTcpFreeConfig(TRUE);
+    PACKET_RECYCLE(p);
     FlowShutdown();
 
     SCFree(p);
index 628171ae06ab75921d3d0c7ca91424af06adafa3..eb6a053adc77c5122cab47e9af7e154083903b6b 100644 (file)
 #include "util-debug.h"
 #include "util-byte.h"
 
+#include "pkt-var.h"
+#include "host.h"
+#include "util-profiling.h"
+
 /**
  *  dsize:[<>]<0-65535>[<><0-65535>];
  */
@@ -790,6 +794,7 @@ cleanup:
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
 
+    PACKET_RECYCLE(p);
     FlowShutdown();
 end:
     SCFree(p);
index 85fcd8f57ef0c650bd880ddf07a966a1d8554fef..73c8dba8e57149a2c19d26020189d0a572437be7 100644 (file)
 #include "util-debug.h"
 #include "util-error.h"
 
+#include "pkt-var.h"
+#include "host.h"
+#include "util-profiling.h"
+
 static int DetectPortCutNot(DetectPort *, DetectPort **);
 static int DetectPortCut(DetectEngineCtx *, DetectPort *, DetectPort *,
                          DetectPort **);
@@ -2444,6 +2448,7 @@ int PortTestMatchReal(uint8_t *raw_eth_pkt, uint16_t pktsize, char *sig,
     FlowInitConfig(FLOW_QUIET);
     Packet *p = UTHBuildPacketFromEth(raw_eth_pkt, pktsize);
     result = UTHPacketMatchSig(p, sig);
+    PACKET_RECYCLE(p);
     FlowShutdown();
     return result;
 }
index 079417472552be0531ff8a292923a9085f7fa783..efbf870b6eee9fea78638bdc8ab78bc09fb80bd0 100644 (file)
 #include "detect-engine.h"
 #include "detect-engine-mpm.h"
 
+#include "pkt-var.h"
+#include "host.h"
+#include "util-profiling.h"
+
 /*                         name             modifiers          value      */
 #define PARSE_REGEX "^\\s*([a-zA-Z][\\w\\d_.]+)\\s*,\\s*([+=-]{1}|==|!=|<|<=|>|>=|isset|notset)\\s*,?\\s*([a-zA-Z][\\w\\d]+|[\\d]{1,10})?\\s*$"
 /* Varnames must begin with a letter */
@@ -1400,6 +1404,7 @@ int DetectFlowintTestPacket01Real()
                 break;
         }
         SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
+        PACKET_RECYCLE(p);
     }
 
     SigGroupCleanup(de_ctx);
@@ -1422,6 +1427,7 @@ end:
     if (de_ctx)
         DetectEngineCtxFree(de_ctx);
 
+    PACKET_RECYCLE(p);
     FlowShutdown();
     SCFree(p);
     return result;
@@ -1736,6 +1742,7 @@ int DetectFlowintTestPacket02Real()
                 break;
         }
         SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
+        PACKET_RECYCLE(p);
     }
 
     SigGroupCleanup(de_ctx);
@@ -2065,6 +2072,7 @@ int DetectFlowintTestPacket03Real()
                 break;
         }
         SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
+        PACKET_RECYCLE(p);
     }
 
     SigGroupCleanup(de_ctx);
index 6908295a9adec69b7fcc035d1d366eafb51a94b2..262621e280c67d491f95ccbcd64367c9df222120 100644 (file)
 #include "util-unittest.h"
 #include "util-debug.h"
 
+#include "pkt-var.h"
+#include "host.h"
+#include "util-profiling.h"
+
 /**
  *  Regex
  *  fragbits: [!+*](MDR)
@@ -524,7 +528,6 @@ static int FragBitsTestParse04 (void) {
 
     DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL);
 
-    FlowShutdown();
 
     de = DetectFragBitsParse("!D");
 
@@ -543,6 +546,8 @@ static int FragBitsTestParse04 (void) {
     if(ret) {
         if (de) SCFree(de);
         if (sm) SCFree(sm);
+        PACKET_RECYCLE(p);
+        FlowShutdown();
         SCFree(p);
         return 1;
     }
@@ -550,6 +555,8 @@ static int FragBitsTestParse04 (void) {
 error:
     if (de) SCFree(de);
     if (sm) SCFree(sm);
+    PACKET_RECYCLE(p);
+    FlowShutdown();
     SCFree(p);
     return 0;
 }
index 7856aa4fe6ae75e63139ca43dbd4513e5d1bb30c..ff985b12e4dd9c2907eee9ae1d1c5c1122a588d5 100644 (file)
 #include "detect-ipproto.h"
 #include "detect-flow.h"
 
+#include "pkt-var.h"
+#include "host.h"
+#include "util-profiling.h"
+#include "decode.h"
+
 #include "flow.h"
 
 #include "util-rule-vars.h"
@@ -2671,8 +2676,10 @@ int SigTestBidirec03 (void) {
     result = UTHCheckPacketMatchResults(p, sids, results, 1);
 
 end:
-    if (p != NULL)
+    if (p != NULL) {
+        PACKET_RECYCLE(p);
         SCFree(p);
+    }
     if (de_ctx != NULL) {
         SigCleanSignatures(de_ctx);
         SigGroupCleanup(de_ctx);
@@ -2815,6 +2822,9 @@ int SigTestBidirec04 (void) {
         result = 1;
     }
 
+    if (p != NULL) {
+        PACKET_RECYCLE(p);
+    }
     FlowShutdown();
     //PatternMatchDestroy(mpm_ctx);
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
index 347355748ee17b73aa1f0cc32b00ac743fec35a1..a94339f1cad133093d9da49de13c2a5f6186cbc3 100644 (file)
@@ -55,6 +55,10 @@ extern int run_mode;
 
 #include "util-debug.h"
 
+#include "pkt-var.h"
+#include "host.h"
+#include "util-profiling.h"
+
 static int DetectReplaceSetup (DetectEngineCtx *, Signature *, char *);
 void DetectReplaceRegisterTests(void);
 
@@ -285,6 +289,7 @@ end:
             DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
         DetectEngineCtxFree(de_ctx);
     }
+    PACKET_RECYCLE(p);
     FlowShutdown();
     SCFree(p);
 
index 9dd9e43112643d07207ad640f59bd3c8f02b427f..d05cdf7207ca62b0153976258cce6232eea0050b 100644 (file)
@@ -8710,6 +8710,7 @@ int SigTest36ContentAndIsdataatKeywords01Real (int mpm_type) {
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     //PatternMatchDestroy(mpm_ctx);
     DetectEngineCtxFree(de_ctx);
+    PACKET_RECYCLE(p);
     FlowShutdown();
 
     SCFree(p);
@@ -8730,6 +8731,9 @@ end:
     if(de_ctx)
              DetectEngineCtxFree(de_ctx);
 
+    if (p != NULL)
+        PACKET_RECYCLE(p);
+
     FlowShutdown();
 
     SCFree(p);
@@ -8842,6 +8846,8 @@ int SigTest37ContentAndIsdataatKeywords02Real (int mpm_type) {
 
     DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
     DetectEngineCtxFree(de_ctx);
+
+    PACKET_RECYCLE(p);
     FlowShutdown();
 
     SCFree(p);
@@ -8860,6 +8866,9 @@ end:
     if(de_ctx)
         DetectEngineCtxFree(de_ctx);
 
+    if (p != NULL)
+        PACKET_RECYCLE(p);
+
     FlowShutdown();
 
     SCFree(p);
@@ -10497,15 +10506,23 @@ end:
     if (de_ctx != NULL)
         DetectEngineCtxFree(de_ctx);
 
-    FlowShutdown();
-    if (p1 != NULL)
+    if (p1 != NULL) {
+        PACKET_RECYCLE(p1);
         SCFree(p1);
-    if (p2 != NULL)
+    }
+    if (p2 != NULL) {
+        PACKET_RECYCLE(p2);
         SCFree(p2);
-    if (p3 != NULL)
+    }
+    if (p3 != NULL) {
+        PACKET_RECYCLE(p3);
         SCFree(p3);
-    if (p4 != NULL)
+    }
+    if (p4 != NULL) {
+        PACKET_RECYCLE(p4);
         SCFree(p4);
+    }
+    FlowShutdown();
     return result;
 }