From: Eric Leblond Date: Tue, 27 Aug 2013 06:52:57 +0000 (+0200) Subject: unittest: recycle packet before exit X-Git-Tag: suricata-2.0beta2~426 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c5bd04f102d3e135d0fcc5ec211b44a745cde02b;p=thirdparty%2Fsuricata.git unittest: recycle packet before exit To avoid an issue with flow validation, we need to recycle the packet before cleaning the flow. --- diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index bb6ed925a5..73c4a08739 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -40,6 +40,10 @@ #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; } /** diff --git a/src/decode-icmpv6.c b/src/decode-icmpv6.c index 1a7866b97e..6a5c6e46d7 100644 --- a/src/decode-icmpv6.c +++ b/src/decode-icmpv6.c @@ -42,6 +42,10 @@ #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; } diff --git a/src/decode-ipv4.c b/src/decode-ipv4.c index 76bed8e863..5922db0b0d 100644 --- a/src/decode-ipv4.c +++ b/src/decode-ipv4.c @@ -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; } diff --git a/src/decode-ipv6.c b/src/decode-ipv6.c index 8059a3df4c..971b55cf3d 100644 --- a/src/decode-ipv6.c +++ b/src/decode-ipv6.c @@ -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; diff --git a/src/decode-raw.c b/src/decode-raw.c index d5910ce4d7..16b8687221 100644 --- a/src/decode-raw.c +++ b/src/decode-raw.c @@ -38,6 +38,11 @@ #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; diff --git a/src/decode-tcp.c b/src/decode-tcp.c index a2e38855dc..e9a83afe1d 100644 --- a/src/decode-tcp.c +++ b/src/decode-tcp.c @@ -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; } diff --git a/src/decode-vlan.c b/src/decode-vlan.c index 11dab31113..ccf61e723a 100644 --- a/src/decode-vlan.c +++ b/src/decode-vlan.c @@ -40,6 +40,10 @@ #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 */ diff --git a/src/detect-content.c b/src/detect-content.c index 0a885cdbab..e2d1a95dec 100644 --- a/src/detect-content.c +++ b/src/detect-content.c @@ -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); diff --git a/src/detect-csum.c b/src/detect-csum.c index 776cd656f8..c30a6dbd73 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -35,6 +35,10 @@ #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); diff --git a/src/detect-dsize.c b/src/detect-dsize.c index 628171ae06..eb6a053adc 100644 --- a/src/detect-dsize.c +++ b/src/detect-dsize.c @@ -37,6 +37,10 @@ #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); diff --git a/src/detect-engine-port.c b/src/detect-engine-port.c index 85fcd8f57e..73c8dba8e5 100644 --- a/src/detect-engine-port.c +++ b/src/detect-engine-port.c @@ -48,6 +48,10 @@ #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; } diff --git a/src/detect-flowint.c b/src/detect-flowint.c index 0794174725..efbf870b6e 100644 --- a/src/detect-flowint.c +++ b/src/detect-flowint.c @@ -40,6 +40,10 @@ #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); diff --git a/src/detect-fragbits.c b/src/detect-fragbits.c index 6908295a9a..262621e280 100644 --- a/src/detect-fragbits.c +++ b/src/detect-fragbits.c @@ -38,6 +38,10 @@ #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; } diff --git a/src/detect-parse.c b/src/detect-parse.c index 7856aa4fe6..ff985b12e4 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -39,6 +39,11 @@ #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); diff --git a/src/detect-replace.c b/src/detect-replace.c index 347355748e..a94339f1ca 100644 --- a/src/detect-replace.c +++ b/src/detect-replace.c @@ -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); diff --git a/src/detect.c b/src/detect.c index 9dd9e43112..d05cdf7207 100644 --- a/src/detect.c +++ b/src/detect.c @@ -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; }