From e176be6fcc02e04f8d6acf9afd0933353085e18e Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sun, 23 Sep 2012 15:56:00 +0200 Subject: [PATCH] Use unlikely for error treatment. When handling error case on SCMallog, SCCalloc or SCStrdup we are in an unlikely case. This patch adds the unlikely() expression to indicate this to gcc. This patch has been obtained via coccinelle. The transformation is the following: @istested@ identifier x; statement S1; identifier func =~ "(SCMalloc|SCStrdup|SCCalloc)"; @@ x = func(...) ... when != x - if (x == NULL) S1 + if (unlikely(x == NULL)) S1 --- src/alert-debuglog.c | 4 +- src/alert-fastlog.c | 4 +- src/alert-pcapinfo.c | 4 +- src/alert-prelude.c | 7 +- src/alert-syslog.c | 4 +- src/alert-unified2-alert.c | 16 ++--- src/app-layer-dcerpc-udp.c | 2 +- src/app-layer-dcerpc.c | 2 +- src/app-layer-detect-proto.c | 4 +- src/app-layer-ftp.c | 2 +- src/app-layer-htp.c | 6 +- src/app-layer-parser.c | 10 +-- src/app-layer-smb.c | 2 +- src/app-layer-smb2.c | 2 +- src/app-layer-smtp.c | 11 ++-- src/app-layer-ssh.c | 2 +- src/app-layer-ssl.c | 2 +- src/conf.c | 12 ++-- src/cuda-packet-batcher.c | 8 +-- src/decode-ethernet.c | 2 +- src/decode-events.c | 2 +- src/decode-gre.c | 6 +- src/decode-icmpv4.c | 14 ++-- src/decode-icmpv6.c | 26 ++++---- src/decode-ipv4.c | 62 +++++++++--------- src/decode-ipv6.c | 14 ++-- src/decode-ppp.c | 8 +-- src/decode-pppoe.c | 10 +-- src/decode-raw.c | 6 +- src/decode-tcp.c | 8 +-- src/decode-vlan.c | 6 +- src/decode.c | 2 +- src/defrag-hash.c | 4 +- src/defrag.c | 10 +-- src/detect-ack.c | 2 +- src/detect-app-layer-event.c | 2 +- src/detect-asn1.c | 2 +- src/detect-byte-extract.c | 2 +- src/detect-bytejump.c | 4 +- src/detect-bytetest.c | 4 +- src/detect-content.c | 4 +- src/detect-csum.c | 4 +- src/detect-depth.c | 2 +- src/detect-detection-filter.c | 4 +- src/detect-distance.c | 2 +- src/detect-dsize.c | 4 +- src/detect-engine-address.c | 10 +-- src/detect-engine-event.c | 4 +- src/detect-engine-iponly.c | 12 ++-- src/detect-engine-mpm.c | 6 +- src/detect-engine-port.c | 8 +-- src/detect-engine-proto.c | 2 +- src/detect-engine-siggroup.c | 4 +- src/detect-engine-state.c | 4 +- src/detect-engine-tag.c | 2 +- src/detect-engine-threshold.c | 2 +- src/detect-engine.c | 8 +-- src/detect-fast-pattern.c | 2 +- src/detect-fileext.c | 2 +- src/detect-filemagic.c | 2 +- src/detect-filemd5.c | 2 +- src/detect-filename.c | 2 +- src/detect-filesize.c | 4 +- src/detect-filestore.c | 2 +- src/detect-flags.c | 28 ++++---- src/detect-flow.c | 2 +- src/detect-flowbits.c | 18 +++--- src/detect-flowint.c | 10 +-- src/detect-flowvar.c | 4 +- src/detect-fragbits.c | 6 +- src/detect-fragoffset.c | 4 +- src/detect-ftpbounce.c | 2 +- src/detect-icmp-id.c | 4 +- src/detect-icmp-seq.c | 2 +- src/detect-icode.c | 2 +- src/detect-id.c | 4 +- src/detect-ipopts.c | 6 +- src/detect-ipproto.c | 4 +- src/detect-isdataat.c | 2 +- src/detect-itype.c | 2 +- src/detect-l3proto.c | 8 +-- src/detect-luajit.c | 4 +- src/detect-mark.c | 4 +- src/detect-msg.c | 4 +- src/detect-offset.c | 2 +- src/detect-parse.c | 18 +++--- src/detect-pcre.c | 2 +- src/detect-pktvar.c | 4 +- src/detect-reference.c | 2 +- src/detect-replace.c | 4 +- src/detect-rev.c | 2 +- src/detect-rpc.c | 2 +- src/detect-seq.c | 2 +- src/detect-sid.c | 2 +- src/detect-ssh-proto-version.c | 2 +- src/detect-ssh-software-version.c | 2 +- src/detect-ssl-version.c | 4 +- src/detect-stream_size.c | 8 +-- src/detect-tag.c | 2 +- src/detect-threshold.c | 4 +- src/detect-tls-version.c | 4 +- src/detect-tls.c | 12 ++-- src/detect-tos.c | 2 +- src/detect-ttl.c | 6 +- src/detect-uricontent.c | 4 +- src/detect-urilen.c | 4 +- src/detect-window.c | 2 +- src/detect-within.c | 2 +- src/detect.c | 102 +++++++++++++++--------------- src/flow-alert-sid.c | 2 +- src/flow-bit.c | 2 +- src/flow-util.c | 4 +- src/flow-var.c | 4 +- src/flow.c | 2 +- src/host.c | 4 +- src/log-droplog.c | 4 +- src/log-file.c | 4 +- src/log-filestore.c | 4 +- src/log-httplog.c | 8 +-- src/log-pcap.c | 9 ++- src/log-tlslog.c | 6 +- src/output.c | 2 +- src/pkt-var.c | 2 +- src/runmode-af-packet.c | 2 +- src/runmode-erf-file.c | 4 +- src/runmode-napatech.c | 72 ++++++++++----------- src/runmode-pcap-file.c | 8 +-- src/runmode-pcap.c | 2 +- src/runmode-pfring.c | 4 +- src/runmodes.c | 2 +- src/source-af-packet.c | 4 +- src/source-erf-dag.c | 5 +- src/source-erf-file.c | 5 +- src/source-napatech.c | 5 +- src/source-pcap-file.c | 2 +- src/source-pcap.c | 5 +- src/source-pfring.c | 2 +- src/stream-tcp-inline.c | 14 ++-- src/stream-tcp-reassemble.c | 44 ++++++------- src/stream-tcp-sack.c | 10 +-- src/stream-tcp.c | 74 +++++++++++----------- src/stream.c | 2 +- src/suricata.c | 7 +- src/tm-queues.c | 2 +- src/tm-threads.c | 6 +- src/tmqh-flow.c | 4 +- src/tmqh-packetpool.c | 2 +- src/util-bloomfilter-counting.c | 2 +- src/util-bloomfilter.c | 2 +- src/util-buffer.c | 2 +- src/util-cuda-handlers.c | 12 ++-- src/util-cuda.c | 4 +- src/util-debug.c | 4 +- src/util-decode-asn1.c | 2 +- src/util-device.c | 2 +- src/util-file.c | 6 +- src/util-hash.c | 6 +- src/util-hashlist.c | 6 +- src/util-mpm-ac-bs.c | 2 +- src/util-mpm-ac-gfbs.c | 2 +- src/util-mpm-ac.c | 2 +- src/util-mpm-b2g-cuda.c | 8 +-- src/util-mpm-b2g.c | 4 +- src/util-mpm-b2gc.c | 2 +- src/util-mpm-b2gm.c | 4 +- src/util-mpm-b3g.c | 4 +- src/util-mpm-wumanber.c | 4 +- src/util-mpm.c | 4 +- src/util-pool.c | 6 +- src/util-profiling-rules.c | 4 +- src/util-profiling.c | 6 +- src/util-radix-tree.c | 36 +++++------ src/util-ringbuffer.c | 4 +- src/util-rohash.c | 2 +- src/util-runmodes.c | 24 +++---- src/util-spm-bm.c | 6 +- src/util-spm.c | 12 ++-- src/util-threshold-config.c | 6 +- src/util-unittest-helper.c | 13 ++-- src/util-unittest.c | 2 +- src/util-var-name.c | 6 +- src/win32-misc.c | 4 +- 182 files changed, 634 insertions(+), 643 deletions(-) diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index 92f5cbad0f..af2eb2da62 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -426,7 +426,7 @@ TmEcode AlertDebugLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, P TmEcode AlertDebugLogThreadInit(ThreadVars *t, void *initdata, void **data) { AlertDebugLogThread *aft = SCMalloc(sizeof(AlertDebugLogThread)); - if (aft == NULL) + if (unlikely(aft == NULL)) return TM_ECODE_FAILED; memset(aft, 0, sizeof(AlertDebugLogThread)); @@ -507,7 +507,7 @@ OutputCtx *AlertDebugLogInitCtx(ConfNode *conf) } OutputCtx *output_ctx = SCMalloc(sizeof(OutputCtx)); - if (output_ctx == NULL) + if (unlikely(output_ctx == NULL)) goto error; memset(output_ctx, 0x00, sizeof(OutputCtx)); diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index 3ed3042a33..22309afdfd 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -282,7 +282,7 @@ TmEcode AlertFastLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pa TmEcode AlertFastLogThreadInit(ThreadVars *t, void *initdata, void **data) { AlertFastLogThread *aft = SCMalloc(sizeof(AlertFastLogThread)); - if (aft == NULL) + if (unlikely(aft == NULL)) return TM_ECODE_FAILED; memset(aft, 0, sizeof(AlertFastLogThread)); if(initdata == NULL) @@ -340,7 +340,7 @@ OutputCtx *AlertFastLogInitCtx(ConfNode *conf) } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) + if (unlikely(output_ctx == NULL)) return NULL; output_ctx->data = logfile_ctx; output_ctx->DeInit = AlertFastLogDeInitCtx; diff --git a/src/alert-pcapinfo.c b/src/alert-pcapinfo.c index a953de8ce0..ec68262e69 100644 --- a/src/alert-pcapinfo.c +++ b/src/alert-pcapinfo.c @@ -121,7 +121,7 @@ TmEcode AlertPcapInfo (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, P TmEcode AlertPcapInfoThreadInit(ThreadVars *t, void *initdata, void **data) { AlertPcapInfoThread *aft = SCMalloc(sizeof(AlertPcapInfoThread)); - if (aft == NULL) + if (unlikely(aft == NULL)) return TM_ECODE_FAILED; memset(aft, 0, sizeof(AlertPcapInfoThread)); if(initdata == NULL) @@ -187,7 +187,7 @@ OutputCtx *AlertPcapInfoInitCtx(ConfNode *conf) } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) + if (unlikely(output_ctx == NULL)) return NULL; output_ctx->data = logfile_ctx; output_ctx->DeInit = AlertPcapInfoDeInitCtx; diff --git a/src/alert-prelude.c b/src/alert-prelude.c index c8b471e064..8abcd77b2b 100644 --- a/src/alert-prelude.c +++ b/src/alert-prelude.c @@ -772,7 +772,7 @@ TmEcode AlertPreludeThreadInit(ThreadVars *t, void *initdata, void **data) } aun = SCMalloc(sizeof(AlertPreludeThread)); - if (aun == NULL) + if (unlikely(aun == NULL)) SCReturnInt(TM_ECODE_FAILED); memset(aun, 0, sizeof(AlertPreludeThread)); @@ -865,7 +865,7 @@ OutputCtx *AlertPreludeInitCtx(ConfNode *conf) } ctx = SCMalloc(sizeof(AlertPreludeCtx)); - if ( ctx == NULL ) { + if (unlikely(ctx == NULL)) { prelude_perror(ret, "Unable to allocate memory"); prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS); SCReturnPtr(NULL, "AlertPreludeCtx"); @@ -880,9 +880,8 @@ OutputCtx *AlertPreludeInitCtx(ConfNode *conf) ctx->log_packet_header = 0; output_ctx = SCMalloc(sizeof(OutputCtx)); - if (output_ctx == NULL) { + if (unlikely(output_ctx == NULL)) { SCFree(ctx); - prelude_perror(ret, "Unable to allocate memory"); prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS); SCReturnPtr(NULL, "AlertPreludeCtx"); diff --git a/src/alert-syslog.c b/src/alert-syslog.c index 806070043b..fd0ce71ef5 100644 --- a/src/alert-syslog.c +++ b/src/alert-syslog.c @@ -158,7 +158,7 @@ OutputCtx *AlertSyslogInitCtx(ConfNode *conf) openlog(ident, LOG_PID|LOG_NDELAY, facility); OutputCtx *output_ctx = SCMalloc(sizeof(OutputCtx)); - if (output_ctx == NULL) { + if (unlikely(output_ctx == NULL)) { SCLogDebug("AlertSyslogInitCtx: Could not create new OutputCtx"); return NULL; } @@ -207,7 +207,7 @@ TmEcode AlertSyslogThreadInit(ThreadVars *t, void *initdata, void **data) } AlertSyslogThread *ast = SCMalloc(sizeof(AlertSyslogThread)); - if (ast == NULL) + if (unlikely(ast == NULL)) return TM_ECODE_FAILED; memset(ast, 0, sizeof(AlertSyslogThread)); diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index 39671e5d0f..07bd44d7f7 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -901,7 +901,7 @@ int Unified2IPv4TypeAlert (ThreadVars *tv, Packet *p, void *data, PacketQueue *p TmEcode Unified2AlertThreadInit(ThreadVars *t, void *initdata, void **data) { Unified2AlertThread *aun = SCMalloc(sizeof(Unified2AlertThread)); - if (aun == NULL) + if (unlikely(aun == NULL)) return TM_ECODE_FAILED; memset(aun, 0, sizeof(Unified2AlertThread)); if(initdata == NULL) @@ -1017,7 +1017,7 @@ OutputCtx *Unified2AlertInitCtx(ConfNode *conf) goto error; OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) + if (unlikely(output_ctx == NULL)) goto error; output_ctx->data = file_ctx; output_ctx->DeInit = Unified2AlertDeInitCtx; @@ -1125,7 +1125,7 @@ static int Unified2Test01 (void) { 0x28, 0x81, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int ret; @@ -1214,7 +1214,7 @@ static int Unified2Test02 (void) { 0x08, 0x0a, 0x00, 0x0a, 0x22, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x05 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int ret; @@ -1309,7 +1309,7 @@ static int Unified2Test03 (void) { 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x0d, 0x0a}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int ret; @@ -1398,7 +1398,7 @@ static int Unified2Test04 (void) { 0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x10, 0x20, 0xdd, 0xe1, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int ret; @@ -1485,7 +1485,7 @@ static int Unified2Test05 (void) { 0x28, 0x81, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int ret; @@ -1569,7 +1569,7 @@ static int Unified2TestRotate01(void) if (lf == NULL) return 0; filename = SCStrdup(lf->filename); - if (filename == NULL) + if (unlikely(filename == NULL)) return 0; memset(&tv, 0, sizeof(ThreadVars)); diff --git a/src/app-layer-dcerpc-udp.c b/src/app-layer-dcerpc-udp.c index 129bcbad1b..fd519baa0d 100644 --- a/src/app-layer-dcerpc-udp.c +++ b/src/app-layer-dcerpc-udp.c @@ -684,7 +684,7 @@ static int DCERPCUDPParse(Flow *f, void *dcerpc_state, static void *DCERPCUDPStateAlloc(void) { void *s = SCMalloc(sizeof(DCERPCUDPState)); - if (s == NULL) + if (unlikely(s == NULL)) return NULL; memset(s, 0, sizeof(DCERPCUDPState)); diff --git a/src/app-layer-dcerpc.c b/src/app-layer-dcerpc.c index b4f7f0f8ed..27162d8991 100644 --- a/src/app-layer-dcerpc.c +++ b/src/app-layer-dcerpc.c @@ -1798,7 +1798,7 @@ static void *DCERPCStateAlloc(void) { SCEnter(); DCERPCState *s = SCMalloc(sizeof(DCERPCState)); - if (s == NULL) { + if (unlikely(s == NULL)) { SCReturnPtr(NULL, "void"); } memset(s, 0, sizeof(DCERPCState)); diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index 26317560b8..18c8494b2e 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -108,7 +108,7 @@ void AlpProtoInit(AlpProtoDetectCtx *ctx) { */ static void AlpProtoAddSignature(AlpProtoDetectCtx *ctx, DetectContentData *co, uint16_t ip_proto, uint16_t proto) { AlpProtoSignature *s = SCMalloc(sizeof(AlpProtoSignature)); - if (s == NULL) { + if (unlikely(s == NULL)) { SCLogError(SC_ERR_FATAL, "Error allocating memory. Signature not loaded. Not enough memory so.. exiting.."); exit(EXIT_FAILURE); } @@ -413,7 +413,7 @@ uint16_t AppLayerDetectGetProtoPMParser(AlpProtoDetectCtx *ctx, searchlen); #else Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) goto end; memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); diff --git a/src/app-layer-ftp.c b/src/app-layer-ftp.c index 985b781804..403f3c4eae 100644 --- a/src/app-layer-ftp.c +++ b/src/app-layer-ftp.c @@ -235,7 +235,7 @@ static uint64_t ftp_state_memcnt = 0; static void *FTPStateAlloc(void) { void *s = SCMalloc(sizeof(FtpState)); - if (s == NULL) + if (unlikely(s == NULL)) return NULL; memset(s, 0, sizeof(FtpState)); diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 7edd41660a..38ea904a81 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -220,7 +220,7 @@ static void *HTPStateAlloc(void) SCEnter(); HtpState *s = SCMalloc(sizeof(HtpState)); - if (s == NULL) + if (unlikely(s == NULL)) goto error; memset(s, 0x00, sizeof(HtpState)); @@ -1791,7 +1791,7 @@ int HTPCallbackRequestBodyData(htp_tx_data_t *d) HtpTxUserData *htud = (HtpTxUserData *) htp_tx_get_user_data(d->tx); if (htud == NULL) { htud = SCMalloc(sizeof(HtpTxUserData)); - if (htud == NULL) { + if (unlikely(htud == NULL)) { SCReturnInt(HOOK_OK); } memset(htud, 0, sizeof(HtpTxUserData)); @@ -1908,7 +1908,7 @@ int HTPCallbackResponseBodyData(htp_tx_data_t *d) HtpTxUserData *htud = (HtpTxUserData *) htp_tx_get_user_data(d->tx); if (htud == NULL) { htud = SCMalloc(sizeof(HtpTxUserData)); - if (htud == NULL) { + if (unlikely(htud == NULL)) { SCReturnInt(HOOK_OK); } memset(htud, 0, sizeof(HtpTxUserData)); diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index e470a7d5dd..f78597a19c 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -1499,7 +1499,7 @@ AppLayerCreateAppLayerProbingParserElement(const char *al_proto_name, (uint8_t *input, uint32_t input_len)) { AppLayerProbingParserElement *pe = SCMalloc(sizeof(AppLayerProbingParserElement)); - if (pe == NULL) { + if (unlikely(pe == NULL)) { return NULL; } @@ -1541,7 +1541,7 @@ static AppLayerProbingParserElement * AppLayerDuplicateAppLayerProbingParserElement(AppLayerProbingParserElement *pe) { AppLayerProbingParserElement *new_pe = SCMalloc(sizeof(AppLayerProbingParserElement)); - if (new_pe == NULL) { + if (unlikely(new_pe == NULL)) { return NULL; } @@ -1576,7 +1576,7 @@ AppLayerInsertNewProbingParserSingleElement(AppLayerProbingParser *pp, { if (pp == NULL) { AppLayerProbingParser *new_pp = SCMalloc(sizeof(AppLayerProbingParser)); - if (new_pp == NULL) + if (unlikely(new_pp == NULL)) return; memset(new_pp, 0, sizeof(AppLayerProbingParser)); @@ -1830,7 +1830,7 @@ int AppLayerProbingParserInfoAdd(AlpProtoDetectCtx *ctx, if (ppi == NULL) { new_ppi = SCMalloc(sizeof(AppLayerProbingParserInfo)); - if (new_ppi == NULL) { + if (unlikely(new_ppi == NULL)) { return -1; } memset(new_ppi, 0, sizeof(AppLayerProbingParserInfo)); @@ -2009,7 +2009,7 @@ static int TestProtocolParser(Flow *f, void *test_state, AppLayerParserState *ps static void *TestProtocolStateAlloc(void) { void *s = SCMalloc(sizeof(TestState)); - if (s == NULL) + if (unlikely(s == NULL)) return NULL; memset(s, 0, sizeof(TestState)); diff --git a/src/app-layer-smb.c b/src/app-layer-smb.c index 251bee1083..3e8eaffa45 100644 --- a/src/app-layer-smb.c +++ b/src/app-layer-smb.c @@ -1292,7 +1292,7 @@ static void *SMBStateAlloc(void) { SCEnter(); void *s = SCMalloc(sizeof(SMBState)); - if (s == NULL) { + if (unlikely(s == NULL)) { SCReturnPtr(NULL, "void"); } diff --git a/src/app-layer-smb2.c b/src/app-layer-smb2.c index 7518648fe1..a2dc7c611b 100644 --- a/src/app-layer-smb2.c +++ b/src/app-layer-smb2.c @@ -503,7 +503,7 @@ static int SMB2Parse(Flow *f, void *smb2_state, AppLayerParserState *pstate, static void *SMB2StateAlloc(void) { void *s = SCMalloc(sizeof(SMB2State)); - if (s == NULL) + if (unlikely(s == NULL)) return NULL; memset(s, 0, sizeof(SMB2State)); diff --git a/src/app-layer-smtp.c b/src/app-layer-smtp.c index e6c9a67d65..a309369a7a 100644 --- a/src/app-layer-smtp.c +++ b/src/app-layer-smtp.c @@ -746,7 +746,7 @@ static int SMTPParseServerRecord(Flow *f, void *alstate, static void *SMTPStateAlloc(void) { SMTPState *smtp_state = SCMalloc(sizeof(SMTPState)); - if (smtp_state == NULL) + if (unlikely(smtp_state == NULL)) return NULL; memset(smtp_state, 0, sizeof(SMTPState)); @@ -765,8 +765,7 @@ static void *SMTPLocalStorageAlloc(void) { /* needed by the mpm */ PatternMatcherQueue *pmq = SCMalloc(sizeof(PatternMatcherQueue)); - if (pmq == NULL) { - /* we need to exit here, since it is load time */ + if (unlikely(pmq == NULL)) { exit(EXIT_FAILURE); } PmqSetup(pmq, 0, @@ -811,15 +810,13 @@ static void SMTPStateFree(void *p) static void SMTPSetMpmState(void) { smtp_mpm_ctx = SCMalloc(sizeof(MpmCtx)); - if (smtp_mpm_ctx == NULL) { - /* we need to exit here, since it is load time */ + if (unlikely(smtp_mpm_ctx == NULL)) { exit(EXIT_FAILURE); } memset(smtp_mpm_ctx, 0, sizeof(MpmCtx)); smtp_mpm_thread_ctx = SCMalloc(sizeof(MpmThreadCtx)); - if (smtp_mpm_thread_ctx == NULL) { - /* we need to exit here, since it is load time */ + if (unlikely(smtp_mpm_thread_ctx == NULL)) { exit(EXIT_FAILURE); } memset(smtp_mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); diff --git a/src/app-layer-ssh.c b/src/app-layer-ssh.c index 5a40c3f17a..b2c6489278 100644 --- a/src/app-layer-ssh.c +++ b/src/app-layer-ssh.c @@ -718,7 +718,7 @@ static int SSHParseClientRecord(Flow *f, void *ssh_state, AppLayerParserState *p static void *SSHStateAlloc(void) { void *s = SCMalloc(sizeof(SshState)); - if (s == NULL) + if (unlikely(s == NULL)) return NULL; memset(s, 0, sizeof(SshState)); diff --git a/src/app-layer-ssl.c b/src/app-layer-ssl.c index 1571636317..ba1d668afd 100644 --- a/src/app-layer-ssl.c +++ b/src/app-layer-ssl.c @@ -857,7 +857,7 @@ int SSLParseServerRecord(Flow *f, void *alstate, AppLayerParserState *pstate, void *SSLStateAlloc(void) { void *ssl_state = SCMalloc(sizeof(SSLState)); - if (ssl_state == NULL) + if (unlikely(ssl_state == NULL)) return NULL; memset(ssl_state, 0, sizeof(SSLState)); ((SSLState*)ssl_state)->client_connp.cert_log_flag = 0; diff --git a/src/conf.c b/src/conf.c index dd11948a1e..be06794861 100644 --- a/src/conf.c +++ b/src/conf.c @@ -78,7 +78,7 @@ ConfNodeNew(void) ConfNode *new; new = SCCalloc(1, sizeof(*new)); - if (new == NULL) { + if (unlikely(new == NULL)) { return NULL; } /* By default we allow an override. */ @@ -129,7 +129,7 @@ ConfGetNode(char *key) /* Need to dup the key for tokenization... */ char *tokstr = SCStrdup(key); - if (tokstr == NULL) { + if (unlikely(tokstr == NULL)) { return NULL; } @@ -198,7 +198,7 @@ ConfSet(char *name, char *val, int allow_override) } else { char *tokstr = SCStrdup(name); - if (tokstr == NULL) { + if (unlikely(tokstr == NULL)) { return 0; } #if defined(__WIN32) || defined(_WIN32) @@ -725,7 +725,7 @@ char *ConfLoadCompleteIncludePath(char *file) size_t path_len = sizeof(char) * (strlen(defaultpath) + strlen(file) + 2); path = SCMalloc(path_len); - if (path == NULL) + if (unlikely(path == NULL)) return NULL; strlcpy(path, defaultpath, path_len); if (path[strlen(path) - 1] != '/') @@ -733,12 +733,12 @@ char *ConfLoadCompleteIncludePath(char *file) strlcat(path, file, path_len); } else { path = SCStrdup(file); - if (path == NULL) + if (unlikely(path == NULL)) return NULL; } } else { path = SCStrdup(file); - if (path == NULL) + if (unlikely(path == NULL)) return NULL; } return path; diff --git a/src/cuda-packet-batcher.c b/src/cuda-packet-batcher.c index 16b1b2448a..35c01a1926 100644 --- a/src/cuda-packet-batcher.c +++ b/src/cuda-packet-batcher.c @@ -439,7 +439,7 @@ void SCCudaPBDeAllocSCCudaPBPacketsBuffer(SCCudaPBPacketsBuffer *pb) SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void) { SCCudaPBPacketsBuffer *pb = SCMalloc(sizeof(SCCudaPBPacketsBuffer)); - if (pb == NULL) { + if (unlikely(pb == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -591,7 +591,7 @@ TmEcode SCCudaPBThreadInit(ThreadVars *tv, void *initdata, void **data) } tctx = SCMalloc(sizeof(SCCudaPBThreadCtx)); - if (tctx == NULL) { + if (unlikely(tctx == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -1149,7 +1149,7 @@ int SCCudaPBTest01(void) SCCudaPBThreadCtx *tctx = NULL; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; ThreadVars tv; @@ -1415,7 +1415,7 @@ int SCCudaPBTest02(void) SCCudaPBThreadCtx *tctx = NULL; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; ThreadVars tv; diff --git a/src/decode-ethernet.c b/src/decode-ethernet.c index 3a257f52da..18cd822d64 100644 --- a/src/decode-ethernet.c +++ b/src/decode-ethernet.c @@ -113,7 +113,7 @@ static int DecodeEthernetTest01 (void) { 0xab, 0xcd }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode-events.c b/src/decode-events.c index c0c649984c..6b06df43ab 100644 --- a/src/decode-events.c +++ b/src/decode-events.c @@ -48,7 +48,7 @@ void AppLayerDecoderEventsModuleRegister(uint16_t alproto, SCEnumCharMap *table) AppLayerDecoderEventsModule *new_dev = SCMalloc(sizeof(AppLayerDecoderEventsModule)); - if (new_dev == NULL) + if (unlikely(new_dev == NULL)) return; new_dev->alproto = alproto; diff --git a/src/decode-gre.c b/src/decode-gre.c index dc5271aa78..b7ae22915c 100644 --- a/src/decode-gre.c +++ b/src/decode-gre.c @@ -267,7 +267,7 @@ static int DecodeGREtest01 (void) { uint8_t raw_gre[] = { 0x00 ,0x6e ,0x62 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -309,7 +309,7 @@ static int DecodeGREtest02 (void) { 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -352,7 +352,7 @@ static int DecodeGREtest03 (void) { 0x01, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode-icmpv4.c b/src/decode-icmpv4.c index c281b3c5a4..9cf1e03424 100644 --- a/src/decode-icmpv4.c +++ b/src/decode-icmpv4.c @@ -320,7 +320,7 @@ static int DecodeICMPV4test01(void) { 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -372,7 +372,7 @@ static int DecodeICMPV4test02(void) { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -421,7 +421,7 @@ static int DecodeICMPV4test03(void) { 0xd1, 0x55, 0xe3, 0x93, 0x8b, 0x12, 0x82, 0xaa, 0x00, 0x28, 0x7c, 0xdd }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -501,7 +501,7 @@ static int DecodeICMPV4test04(void) { 0xa0, 0x02, 0x16, 0xd0, 0x72, 0x04, 0x00, 0x00, 0x02, 0x04, 0x05, 0x8a, 0x04, 0x02, 0x08, 0x0a }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -571,7 +571,7 @@ static int DecodeICMPV4test05(void) { 0x23, 0x04, 0x18, 0x00, 0x50, 0xd2, 0x08, 0xc2, 0x48, }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -676,7 +676,7 @@ static int ICMPV4InvalidType07(void) { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -720,7 +720,7 @@ static int DecodeICMPV4test08(void) { 0x08, 0x00, 0x78, 0x47, 0xfc, 0x55, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode-icmpv6.c b/src/decode-icmpv6.c index 01023a05fa..d0150535d5 100644 --- a/src/decode-icmpv6.c +++ b/src/decode-icmpv6.c @@ -367,7 +367,7 @@ static int ICMPV6ParamProbTest01(void) 0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -439,7 +439,7 @@ static int ICMPV6PktTooBigTest01(void) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -513,7 +513,7 @@ static int ICMPV6TimeExceedTest01(void) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -589,7 +589,7 @@ static int ICMPV6DestUnreachTest01(void) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -657,7 +657,7 @@ static int ICMPV6EchoReqTest01(void) 0x80, 0x00, 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -710,7 +710,7 @@ static int ICMPV6EchoRepTest01(void) 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -770,7 +770,7 @@ static int ICMPV6ParamProbTest02(void) 0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -831,7 +831,7 @@ static int ICMPV6PktTooBigTest02(void) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -883,7 +883,7 @@ static int ICMPV6TimeExceedTest02(void) /* The icmpv6 header is broken in the checksum (so we dont have a complete header) */ Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -932,7 +932,7 @@ static int ICMPV6DestUnreachTest02(void) 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -977,7 +977,7 @@ static int ICMPV6EchoReqTest02(void) 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -1022,7 +1022,7 @@ static int ICMPV6EchoRepTest02(void) 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; @@ -1070,7 +1070,7 @@ static int ICMPV6PayloadTest01(void) 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; diff --git a/src/decode-ipv4.c b/src/decode-ipv4.c index f96b09fc04..7dbaaf0192 100644 --- a/src/decode-ipv4.c +++ b/src/decode-ipv4.c @@ -638,7 +638,7 @@ void DecodeIPV4OptionsPrint(Packet *p) { int DecodeIPV4OptionsNONETest01(void) { uint8_t raw_opts[] = { }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; uint8_t *data = (uint8_t *)p; uint16_t i; @@ -674,7 +674,7 @@ int DecodeIPV4OptionsEOLTest01(void) { IPV4_OPT_EOL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; uint8_t *data = (uint8_t *)p; uint16_t i; @@ -710,7 +710,7 @@ int DecodeIPV4OptionsNOPTest01(void) { IPV4_OPT_NOP, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; uint8_t *data = (uint8_t *)p; uint16_t i; @@ -750,7 +750,7 @@ int DecodeIPV4OptionsRRTest01(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -784,7 +784,7 @@ int DecodeIPV4OptionsRRTest02(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -813,7 +813,7 @@ int DecodeIPV4OptionsRRTest03(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -842,7 +842,7 @@ int DecodeIPV4OptionsRRTest04(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -867,7 +867,7 @@ int DecodeIPV4OptionsQSTest01(void) { IPV4_OPT_QS, 0x08, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -897,7 +897,7 @@ int DecodeIPV4OptionsQSTest02(void) { IPV4_OPT_QS, 0x07, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -926,7 +926,7 @@ int DecodeIPV4OptionsTSTest01(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -960,7 +960,7 @@ int DecodeIPV4OptionsTSTest02(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -989,7 +989,7 @@ int DecodeIPV4OptionsTSTest03(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1018,7 +1018,7 @@ int DecodeIPV4OptionsTSTest04(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1044,7 +1044,7 @@ int DecodeIPV4OptionsSECTest01(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1075,7 +1075,7 @@ int DecodeIPV4OptionsSECTest02(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1104,7 +1104,7 @@ int DecodeIPV4OptionsLSRRTest01(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1138,7 +1138,7 @@ int DecodeIPV4OptionsLSRRTest02(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1167,7 +1167,7 @@ int DecodeIPV4OptionsLSRRTest03(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1196,7 +1196,7 @@ int DecodeIPV4OptionsLSRRTest04(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1223,7 +1223,7 @@ int DecodeIPV4OptionsCIPSOTest01(void) { 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1253,7 +1253,7 @@ int DecodeIPV4OptionsSIDTest01(void) { IPV4_OPT_SID, 0x04, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1283,7 +1283,7 @@ int DecodeIPV4OptionsSIDTest02(void) { IPV4_OPT_SID, 0x05, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1312,7 +1312,7 @@ int DecodeIPV4OptionsSSRRTest01(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1346,7 +1346,7 @@ int DecodeIPV4OptionsSSRRTest02(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1375,7 +1375,7 @@ int DecodeIPV4OptionsSSRRTest03(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1404,7 +1404,7 @@ int DecodeIPV4OptionsSSRRTest04(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1429,7 +1429,7 @@ int DecodeIPV4OptionsRTRALTTest01(void) { IPV4_OPT_RTRALT, 0x04, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1459,7 +1459,7 @@ int DecodeIPV4OptionsRTRALTTest02(void) { IPV4_OPT_RTRALT, 0x05, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; int rc; @@ -1545,7 +1545,7 @@ int DecodeIPV4DefragTest01(void) }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -1683,7 +1683,7 @@ int DecodeIPV4DefragTest02(void) }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -1812,7 +1812,7 @@ int DecodeIPV4DefragTest03(void) Flow *f = NULL; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode-ipv6.c b/src/decode-ipv6.c index a3bebb7689..67e4ac6f09 100644 --- a/src/decode-ipv6.c +++ b/src/decode-ipv6.c @@ -712,12 +712,12 @@ static int DecodeIPV6FragTest01 (void) { 0x20, 0x20, 0x20, 0x20, }; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) - return 0; + if (unlikely(p1 == NULL)) + return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { - SCFree(p1); - return 0; + if (unlikely(p2 == NULL)) { + SCFree(p1); + return 0; } ThreadVars tv; DecodeThreadVars dtv; @@ -789,8 +789,8 @@ static int DecodeIPV6RouteTest01 (void) { 0xfa, 0x87, 0x00, 0x00, }; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) - return 0; + if (unlikely(p1 == NULL)) + return 0; ThreadVars tv; DecodeThreadVars dtv; int result = 0; diff --git a/src/decode-ppp.c b/src/decode-ppp.c index 8085603e8b..9c465a8ef1 100644 --- a/src/decode-ppp.c +++ b/src/decode-ppp.c @@ -139,7 +139,7 @@ void DecodePPP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u static int DecodePPPtest01 (void) { uint8_t raw_ppp[] = { 0xff, 0x03, 0x00, 0x21, 0x45, 0xc0, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -173,7 +173,7 @@ static int DecodePPPtest02 (void) { 0x17, 0x6d, 0x0b, 0xba, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x10, 0x20, 0xdd, 0xe1, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -209,7 +209,7 @@ static int DecodePPPtest03 (void) { 0x17, 0x6d, 0x0b, 0xba, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x10, 0x20, 0xdd, 0xe1, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -268,7 +268,7 @@ static int DecodePPPtest04 (void) { 0x17, 0x6d, 0x0b, 0xba, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x10, 0x20, 0xdd, 0xe1, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode-pppoe.c b/src/decode-pppoe.c index 647d33973b..1dd260a6e1 100644 --- a/src/decode-pppoe.c +++ b/src/decode-pppoe.c @@ -229,7 +229,7 @@ static int DecodePPPOEtest01 (void) { uint8_t raw_pppoe[] = { 0x11, 0x00, 0x00, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -268,7 +268,7 @@ static int DecodePPPOEtest02 (void) { 0x46, 0x47, 0x48, 0x49 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -317,7 +317,7 @@ static int DecodePPPOEtest03 (void) { }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -350,7 +350,7 @@ static int DecodePPPOEtest04 (void) { }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -386,7 +386,7 @@ static int DecodePPPOEtest05 (void) { }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode-raw.c b/src/decode-raw.c index 97c479fe68..2b4db29bdd 100644 --- a/src/decode-raw.c +++ b/src/decode-raw.c @@ -84,7 +84,7 @@ static int DecodeRawTest01 (void) { 0x04, 0x02, 0x08, 0x0a, 0x00, 0xdd, 0x1a, 0x39, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x02 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -130,7 +130,7 @@ static int DecodeRawTest02 (void) { 0x02, 0x04, 0x05, 0xb4, 0x01, 0x01, 0x04, 0x02 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -176,7 +176,7 @@ static int DecodeRawTest03 (void) { 0x20, 0x6b, 0x65, 0x79, 0x3b }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode-tcp.c b/src/decode-tcp.c index ae32929158..4f96f3291f 100644 --- a/src/decode-tcp.c +++ b/src/decode-tcp.c @@ -302,7 +302,7 @@ static int TCPGetWscaleTest01(void) 0x04, 0x02, 0x08, 0x0a, 0x00, 0x62, 0x88, 0x28, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x02}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ip4h; ThreadVars tv; @@ -350,7 +350,7 @@ static int TCPGetWscaleTest02(void) 0x04, 0x02, 0x08, 0x0a, 0x00, 0x62, 0x88, 0x28, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x0f}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ip4h; ThreadVars tv; @@ -396,7 +396,7 @@ static int TCPGetWscaleTest03(void) 0x7c, 0x70, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x00, 0x62, 0x88, 0x9e, 0x00, 0x00, 0x00, 0x00}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ip4h; ThreadVars tv; @@ -446,7 +446,7 @@ static int TCPGetSackTest01(void) 0xf1, 0x59, 0x13, 0xfc, 0xf1, 0x59, 0x1f, 0x64, 0xf1, 0x59, 0x08, 0x94, 0xf1, 0x59, 0x0e, 0x48 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ip4h; ThreadVars tv; diff --git a/src/decode-vlan.c b/src/decode-vlan.c index 4c1841e012..4bbaab424d 100644 --- a/src/decode-vlan.c +++ b/src/decode-vlan.c @@ -112,7 +112,7 @@ void DecodeVLAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, static int DecodeVLANtest01 (void) { uint8_t raw_vlan[] = { 0x00, 0x20, 0x08 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -149,7 +149,7 @@ static int DecodeVLANtest02 (void) { 0x3c, 0x4c, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x00, 0x04, 0xf0, 0xc8, 0x01, 0x99, 0xa3, 0xf3}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -187,7 +187,7 @@ static int DecodeVLANtest03 (void) { 0x3c, 0x4c, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x00, 0x04, 0xf0, 0xc8, 0x01, 0x99, 0xa3, 0xf3}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/decode.c b/src/decode.c index 91fca2869a..99c664e1e0 100644 --- a/src/decode.c +++ b/src/decode.c @@ -85,7 +85,7 @@ void DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, Packet *PacketGetFromAlloc(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) { + if (unlikely(p == NULL)) { return NULL; } diff --git a/src/defrag-hash.c b/src/defrag-hash.c index e7dc32b2ff..f617d3f62a 100644 --- a/src/defrag-hash.c +++ b/src/defrag-hash.c @@ -46,7 +46,7 @@ DefragTracker *DefragTrackerAlloc(void) { (void) SC_ATOMIC_ADD(defrag_memuse, sizeof(DefragTracker)); DefragTracker *dt = SCMalloc(sizeof(DefragTracker)); - if (dt == NULL) + if (unlikely(dt == NULL)) goto error; memset(dt, 0x00, sizeof(DefragTracker)); @@ -184,7 +184,7 @@ void DefragInitConfig(char quiet) exit(EXIT_FAILURE); } defragtracker_hash = SCCalloc(defrag_config.hash_size, sizeof(DefragTrackerHashRow)); - if (defragtracker_hash == NULL) { + if (unlikely(defragtracker_hash == NULL)) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in DefragTrackerInitConfig. Exiting..."); exit(EXIT_FAILURE); } diff --git a/src/defrag.c b/src/defrag.c index ee7e43729b..cb8fba25a0 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -173,7 +173,7 @@ DefragContextNew(void) DefragContext *dc; dc = SCCalloc(1, sizeof(*dc)); - if (dc == NULL) + if (unlikely(dc == NULL)) return NULL; /* Initialize the pool of trackers. */ @@ -912,7 +912,7 @@ BuildTestPacket(uint16_t id, uint16_t off, int mf, const char content, IPV4Hdr ip4h; p = SCCalloc(1, sizeof(*p) + default_packet_size); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; PACKET_INITIALIZE(p); @@ -941,7 +941,7 @@ BuildTestPacket(uint16_t id, uint16_t off, int mf, const char content, SET_IPV4_DST_ADDR(p, &p->dst); pcontent = SCCalloc(1, content_len); - if (pcontent == NULL) + if (unlikely(pcontent == NULL)) return NULL; memset(pcontent, content, content_len); PacketCopyDataOffset(p, hlen, pcontent, content_len); @@ -984,7 +984,7 @@ IPV6BuildTestPacket(uint32_t id, uint16_t off, int mf, const char content, IPV6Hdr ip6h; p = SCCalloc(1, sizeof(*p) + default_packet_size); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; PACKET_INITIALIZE(p); @@ -1016,7 +1016,7 @@ IPV6BuildTestPacket(uint32_t id, uint16_t off, int mf, const char content, p->ip6eh.ip6fh->ip6fh_offlg = htons((off << 3) | mf); pcontent = SCCalloc(1, content_len); - if (pcontent == NULL) + if (unlikely(pcontent == NULL)) return NULL; memset(pcontent, content, content_len); PacketCopyDataOffset(p, sizeof(IPV6Hdr) + sizeof(IPV6FragHdr), pcontent, content_len); diff --git a/src/detect-ack.c b/src/detect-ack.c index e3ac7d3f62..e82aef2fc9 100644 --- a/src/detect-ack.c +++ b/src/detect-ack.c @@ -97,7 +97,7 @@ static int DetectAckSetup(DetectEngineCtx *de_ctx, Signature *s, char *optstr) SigMatch *sm = NULL; data = SCMalloc(sizeof(DetectAckData)); - if (data == NULL) + if (unlikely(data == NULL)) goto error; sm = SigMatchAlloc(); diff --git a/src/detect-app-layer-event.c b/src/detect-app-layer-event.c index bf9aae40f0..415c5db02e 100644 --- a/src/detect-app-layer-event.c +++ b/src/detect-app-layer-event.c @@ -125,7 +125,7 @@ static DetectAppLayerEventData *DetectAppLayerEventParse(const char *arg) return NULL; DetectAppLayerEventData *aled = SCMalloc(sizeof(DetectAppLayerEventData)); - if (aled == NULL) + if (unlikely(aled == NULL)) return NULL; aled->alproto = alproto; aled->event_id = event_id; diff --git a/src/detect-asn1.c b/src/detect-asn1.c index 22034be461..f9cb41e36b 100644 --- a/src/detect-asn1.c +++ b/src/detect-asn1.c @@ -259,7 +259,7 @@ DetectAsn1Data *DetectAsn1Parse(char *asn1str) { } fd = SCMalloc(sizeof(DetectAsn1Data)); - if (fd == NULL) { + if (unlikely(fd == NULL)) { exit(EXIT_FAILURE); } memset(fd, 0x00, sizeof(DetectAsn1Data)); diff --git a/src/detect-byte-extract.c b/src/detect-byte-extract.c index 8bbbb295cf..35c2e27c51 100644 --- a/src/detect-byte-extract.c +++ b/src/detect-byte-extract.c @@ -260,7 +260,7 @@ static inline DetectByteExtractData *DetectByteExtractParse(char *arg) } bed = SCMalloc(sizeof(DetectByteExtractData)); - if (bed == NULL) + if (unlikely(bed == NULL)) goto error; memset(bed, 0, sizeof(DetectByteExtractData)); diff --git a/src/detect-bytejump.c b/src/detect-bytejump.c index 359e684ce5..ee25e7521d 100644 --- a/src/detect-bytejump.c +++ b/src/detect-bytejump.c @@ -395,7 +395,7 @@ DetectBytejumpData *DetectBytejumpParse(char *optstr, char **offset) /* Initialize the data */ data = SCMalloc(sizeof(DetectBytejumpData)); - if (data == NULL) + if (unlikely(data == NULL)) goto error; data->base = DETECT_BYTEJUMP_BASE_UNSET; data->flags = 0; @@ -1223,7 +1223,7 @@ int DetectByteJumpTestPacket03(void) uint8_t *buf = NULL; uint16_t buflen = 0; buf = SCMalloc(4); - if (buf == NULL) { + if (unlikely(buf == NULL)) { printf("malloc failed\n"); exit(EXIT_FAILURE); } diff --git a/src/detect-bytetest.c b/src/detect-bytetest.c index 51705e19a0..e1c86ba157 100644 --- a/src/detect-bytetest.c +++ b/src/detect-bytetest.c @@ -293,7 +293,7 @@ DetectBytetestData *DetectBytetestParse(char *optstr, char **value, char **offse /* Initialize the data */ data = SCMalloc(sizeof(DetectBytetestData)); - if (data == NULL) + if (unlikely(data == NULL)) goto error; data->base = DETECT_BYTETEST_BASE_UNSET; data->flags = 0; @@ -1394,7 +1394,7 @@ int DetectByteTestTestPacket03(void) uint8_t *buf = NULL; uint16_t buflen = 0; buf = SCMalloc(4); - if (buf == NULL) { + if (unlikely(buf == NULL)) { printf("malloc failed\n"); exit(EXIT_FAILURE); } diff --git a/src/detect-content.c b/src/detect-content.c index 7ff1dd90c9..f09c77686c 100644 --- a/src/detect-content.c +++ b/src/detect-content.c @@ -222,7 +222,7 @@ DetectContentData *DetectContentParse (char *contentstr) } cd = SCMalloc(sizeof(DetectContentData) + len); - if (cd == NULL) { + if (unlikely(cd == NULL)) { SCFree(str); exit(EXIT_FAILURE); } @@ -620,7 +620,7 @@ int DetectContentLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize, ch int result = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; diff --git a/src/detect-csum.c b/src/detect-csum.c index 418f87c67d..3b7cac7241 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -186,13 +186,13 @@ static int DetectCsumParseArg(const char *key, DetectCsumData *cd) if (key[0] == '\"' && key[strlen(key) - 1] == '\"') { str = SCStrdup(key + 1); - if (str == NULL) { + if (unlikely(str == NULL)) { goto error; } str[strlen(key) - 2] = '\0'; } else { str = SCStrdup(key); - if (str == NULL) { + if (unlikely(str == NULL)) { goto error; } } diff --git a/src/detect-depth.c b/src/detect-depth.c index a6c4b31c0d..c167a301ca 100644 --- a/src/detect-depth.c +++ b/src/detect-depth.c @@ -62,7 +62,7 @@ static int DetectDepthSetup (DetectEngineCtx *de_ctx, Signature *s, char *depths /* strip "'s */ if (depthstr[0] == '\"' && depthstr[strlen(depthstr) - 1] == '\"') { str = SCStrdup(depthstr + 1); - if (str == NULL) + if (unlikely(str == NULL)) goto error; str[strlen(depthstr) - 2] = '\0'; dubbed = 1; diff --git a/src/detect-detection-filter.c b/src/detect-detection-filter.c index e4aeed5264..4b74765f15 100644 --- a/src/detect-detection-filter.c +++ b/src/detect-detection-filter.c @@ -118,7 +118,7 @@ DetectThresholdData *DetectDetectionFilterParse (char *rawstr) { int i = 0; copy_str = SCStrdup(rawstr); - if (copy_str == NULL) { + if (unlikely(copy_str == NULL)) { goto error; } @@ -147,7 +147,7 @@ DetectThresholdData *DetectDetectionFilterParse (char *rawstr) { } df = SCMalloc(sizeof(DetectThresholdData)); - if (df == NULL) + if (unlikely(df == NULL)) goto error; memset(df,0,sizeof(DetectThresholdData)); diff --git a/src/detect-distance.c b/src/detect-distance.c index 75220670a4..10afa11b4c 100644 --- a/src/detect-distance.c +++ b/src/detect-distance.c @@ -69,7 +69,7 @@ static int DetectDistanceSetup (DetectEngineCtx *de_ctx, Signature *s, /* strip "'s */ if (distancestr[0] == '\"' && distancestr[strlen(distancestr) - 1] == '\"') { str = SCStrdup(distancestr + 1); - if (str == NULL) + if (unlikely(str == NULL)) goto error; str[strlen(distancestr) - 2] = '\0'; dubbed = 1; diff --git a/src/detect-dsize.c b/src/detect-dsize.c index d8a1afcfe7..d033fd52f9 100644 --- a/src/detect-dsize.c +++ b/src/detect-dsize.c @@ -184,7 +184,7 @@ DetectDsizeData *DetectDsizeParse (char *rawstr) } dd = SCMalloc(sizeof(DetectDsizeData)); - if (dd == NULL) + if (unlikely(dd == NULL)) goto error; dd->dsize = 0; dd->dsize2 = 0; @@ -720,7 +720,7 @@ int DetectDsizeIcmpv6Test01 (void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV6Hdr ip6h; ThreadVars tv; diff --git a/src/detect-engine-address.c b/src/detect-engine-address.c index 001fd7ba85..b90a23a8cf 100644 --- a/src/detect-engine-address.c +++ b/src/detect-engine-address.c @@ -73,7 +73,7 @@ static uint32_t detect_address_group_head_free_cnt = 0; DetectAddress *DetectAddressInit(void) { DetectAddress *ag = SCMalloc(sizeof(DetectAddress)); - if (ag == NULL) + if (unlikely(ag == NULL)) return NULL; memset(ag, 0, sizeof(DetectAddress)); @@ -602,7 +602,7 @@ int DetectAddressParseString(DetectAddress *dd, char *str) char *mask = NULL; int r = 0; - if (ipdup == NULL) + if (unlikely(ipdup == NULL)) return -1; SCLogDebug("str %s", str); @@ -978,7 +978,7 @@ int DetectAddressParse2(DetectAddressHead *gh, DetectAddressHead *ghn, char *s, temp_rule_var_address = rule_var_address; if ((negate + n_set) % 2) { temp_rule_var_address = SCMalloc(strlen(rule_var_address) + 3); - if (temp_rule_var_address == NULL) + if (unlikely(temp_rule_var_address == NULL)) goto error; snprintf(temp_rule_var_address, strlen(rule_var_address) + 3, "[%s]", rule_var_address); @@ -1027,7 +1027,7 @@ int DetectAddressParse2(DetectAddressHead *gh, DetectAddressHead *ghn, char *s, temp_rule_var_address = rule_var_address; if ((negate + n_set) % 2) { temp_rule_var_address = SCMalloc(strlen(rule_var_address) + 3); - if (temp_rule_var_address == NULL) + if (unlikely(temp_rule_var_address == NULL)) goto error; snprintf(temp_rule_var_address, strlen(rule_var_address) + 3, "[%s]", rule_var_address); @@ -1344,7 +1344,7 @@ error: DetectAddressHead *DetectAddressHeadInit(void) { DetectAddressHead *gh = SCMalloc(sizeof(DetectAddressHead)); - if (gh == NULL) + if (unlikely(gh == NULL)) return NULL; memset(gh, 0, sizeof(DetectAddressHead)); diff --git a/src/detect-engine-event.c b/src/detect-engine-event.c index bde932042a..d276313de8 100644 --- a/src/detect-engine-event.c +++ b/src/detect-engine-event.c @@ -168,7 +168,7 @@ DetectEngineEventData *DetectEngineEventParse (char *rawstr) } de = SCMalloc(sizeof(DetectEngineEventData)); - if (de == NULL) + if (unlikely(de == NULL)) goto error; de->event = DEvents[i].code; @@ -335,7 +335,7 @@ int EngineEventTestParse05 (void) { */ int EngineEventTestParse06 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; diff --git a/src/detect-engine-iponly.c b/src/detect-engine-iponly.c index 355b2b4ef7..c14c610d22 100644 --- a/src/detect-engine-iponly.c +++ b/src/detect-engine-iponly.c @@ -70,7 +70,7 @@ static IPOnlyCIDRItem *IPOnlyCIDRItemNew() { IPOnlyCIDRItem *item = NULL; item = SCMalloc(sizeof(IPOnlyCIDRItem)); - if (item == NULL) + if (unlikely(item == NULL)) SCReturnPtr(NULL, "NULL"); memset(item, 0, sizeof(IPOnlyCIDRItem)); @@ -108,7 +108,7 @@ static int IPOnlyCIDRItemParseSingle(IPOnlyCIDRItem *dd, char *str) char *mask = NULL; int r = 0; - if (ipdup == NULL) + if (unlikely(ipdup == NULL)) return -1; SCLogDebug("str %s", str); @@ -508,7 +508,7 @@ static SigNumArray *SigNumArrayNew(DetectEngineCtx *de_ctx, { SigNumArray *new = SCMalloc(sizeof(SigNumArray)); - if (new == NULL){ + if (unlikely(new == NULL)) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigNumArrayNew. Exiting..."); exit(EXIT_FAILURE); } @@ -538,7 +538,7 @@ static SigNumArray *SigNumArrayNew(DetectEngineCtx *de_ctx, static SigNumArray *SigNumArrayCopy(SigNumArray *orig) { SigNumArray *new = SCMalloc(sizeof(SigNumArray)); - if (new == NULL) { + if (unlikely(new == NULL)) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigNumArrayCopy. Exiting..."); exit(EXIT_FAILURE); } @@ -638,7 +638,7 @@ static IPOnlyCIDRItem *IPOnlyCIDRListParse2(char *s, int negate) if ((negate + n_set) % 2) { temp_rule_var_address = SCMalloc(strlen(rule_var_address) + 3); - if (temp_rule_var_address == NULL) { + if (unlikely(temp_rule_var_address == NULL)) { goto error; } @@ -697,7 +697,7 @@ static IPOnlyCIDRItem *IPOnlyCIDRListParse2(char *s, int negate) temp_rule_var_address = rule_var_address; if ((negate + n_set) % 2) { temp_rule_var_address = SCMalloc(strlen(rule_var_address) + 3); - if (temp_rule_var_address == NULL) { + if (unlikely(temp_rule_var_address == NULL)) { goto error; } snprintf(temp_rule_var_address, strlen(rule_var_address) + 3, diff --git a/src/detect-engine-mpm.c b/src/detect-engine-mpm.c index 3646643a7f..b0f3170b6e 100644 --- a/src/detect-engine-mpm.c +++ b/src/detect-engine-mpm.c @@ -1129,7 +1129,7 @@ char UricontentHashCompareFunc(void *data1, uint16_t len1, void *data2, uint16_t ContentHash *ContentHashAlloc(DetectContentData *ptr) { ContentHash *ch = SCMalloc(sizeof(ContentHash)); - if (ch == NULL) + if (unlikely(ch == NULL)) return NULL; ch->ptr = ptr; @@ -1141,7 +1141,7 @@ ContentHash *ContentHashAlloc(DetectContentData *ptr) { UricontentHash *UricontentHashAlloc(DetectContentData *ptr) { UricontentHash *ch = SCMalloc(sizeof(UricontentHash)); - if (ch == NULL) + if (unlikely(ch == NULL)) return NULL; ch->ptr = ptr; @@ -2948,7 +2948,7 @@ uint32_t DetectPatternGetId(MpmPatternIdStore *ht, void *ctx, uint8_t sm_list) PatIntId id = 0; e = SCMalloc(sizeof(MpmPatternIdTableElmt)); - if (e == NULL) { + if (unlikely(e == NULL)) { exit(EXIT_FAILURE); } diff --git a/src/detect-engine-port.c b/src/detect-engine-port.c index afa7e88bdb..1b8c10445e 100644 --- a/src/detect-engine-port.c +++ b/src/detect-engine-port.c @@ -67,7 +67,7 @@ static uint32_t detect_port_free_cnt = 0; */ DetectPort *DetectPortInit(void) { DetectPort *dp = SCMalloc(sizeof(DetectPort)); - if (dp == NULL) + if (unlikely(dp == NULL)) return NULL; memset(dp, 0, sizeof(DetectPort)); @@ -1059,7 +1059,7 @@ static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s, temp_rule_var_port = rule_var_port; if (negate == 1 || n_set == 1) { temp_rule_var_port = SCMalloc(strlen(rule_var_port) + 3); - if (temp_rule_var_port == NULL) + if (unlikely(temp_rule_var_port == NULL)) goto error; snprintf(temp_rule_var_port, strlen(rule_var_port) + 3, "[%s]", rule_var_port); @@ -1115,7 +1115,7 @@ static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s, temp_rule_var_port = rule_var_port; if ((negate + n_set) % 2) { temp_rule_var_port = SCMalloc(strlen(rule_var_port) + 3); - if (temp_rule_var_port == NULL) + if (unlikely(temp_rule_var_port == NULL)) goto error; snprintf(temp_rule_var_port, strlen(rule_var_port) + 3, "[%s]", rule_var_port); @@ -1383,7 +1383,7 @@ DetectPort *PortParse(char *str) { char *port2 = NULL; DetectPort *dp = NULL; - if (portdup == NULL) { + if (unlikely(portdup == NULL)) { return NULL; } dp = DetectPortInit(); diff --git a/src/detect-engine-proto.c b/src/detect-engine-proto.c index 9528964672..7994e486e6 100644 --- a/src/detect-engine-proto.c +++ b/src/detect-engine-proto.c @@ -54,7 +54,7 @@ DetectProto *DetectProtoInit(void) { DetectProto *dp = SCMalloc(sizeof(DetectProto)); - if (dp == NULL) + if (unlikely(dp == NULL)) return NULL; memset(dp,0,sizeof(DetectProto)); diff --git a/src/detect-engine-siggroup.c b/src/detect-engine-siggroup.c index 8c833bd76b..c5344497ce 100644 --- a/src/detect-engine-siggroup.c +++ b/src/detect-engine-siggroup.c @@ -92,7 +92,7 @@ void SigGroupHeadInitDataFree(SigGroupHeadInitData *sghid) { static SigGroupHeadInitData *SigGroupHeadInitDataAlloc(uint32_t size) { SigGroupHeadInitData *sghid = SCMalloc(sizeof(SigGroupHeadInitData)); - if (sghid == NULL) + if (unlikely(sghid == NULL)) return NULL; memset(sghid, 0x00, sizeof(SigGroupHeadInitData)); @@ -142,7 +142,7 @@ void SigGroupHeadStore(DetectEngineCtx *de_ctx, SigGroupHead *sgh) { static SigGroupHead *SigGroupHeadAlloc(DetectEngineCtx *de_ctx, uint32_t size) { SigGroupHead *sgh = SCMalloc(sizeof(SigGroupHead)); - if (sgh == NULL) + if (unlikely(sgh == NULL)) return NULL; memset(sgh, 0, sizeof(SigGroupHead)); diff --git a/src/detect-engine-state.c b/src/detect-engine-state.c index 5bf178cb66..3b24b02d57 100644 --- a/src/detect-engine-state.c +++ b/src/detect-engine-state.c @@ -130,7 +130,7 @@ DeStateStore *DeStateStoreAlloc(void) { SCEnter(); DeStateStore *d = SCMalloc(sizeof(DeStateStore)); - if (d == NULL) { + if (unlikely(d == NULL)) { SCReturnPtr(NULL, "DeStateStore"); } memset(d, 0x00, sizeof(DeStateStore)); @@ -165,7 +165,7 @@ DetectEngineState *DetectEngineStateAlloc(void) { SCEnter(); DetectEngineState *d = SCMalloc(sizeof(DetectEngineState)); - if (d == NULL) { + if (unlikely(d == NULL)) { SCReturnPtr(NULL, "DetectEngineState"); } memset(d, 0x00, sizeof(DetectEngineState)); diff --git a/src/detect-engine-tag.c b/src/detect-engine-tag.c index 08fca69e6c..63d930a71d 100644 --- a/src/detect-engine-tag.c +++ b/src/detect-engine-tag.c @@ -65,7 +65,7 @@ void TagRestartCtx() { static DetectTagDataEntry *DetectTagDataCopy(DetectTagDataEntry *dtd) { DetectTagDataEntry *tde = SCMalloc(sizeof(DetectTagDataEntry)); - if (tde == NULL) { + if (unlikely(tde == NULL)) { return NULL; } memset(tde, 0, sizeof(DetectTagDataEntry)); diff --git a/src/detect-engine-threshold.c b/src/detect-engine-threshold.c index a06338cd6f..3c69609089 100644 --- a/src/detect-engine-threshold.c +++ b/src/detect-engine-threshold.c @@ -175,7 +175,7 @@ static inline DetectThresholdEntry *DetectThresholdEntryAlloc(DetectThresholdDat SCEnter(); DetectThresholdEntry *ste = SCMalloc(sizeof(DetectThresholdEntry)); - if (ste == NULL) { + if (unlikely(ste == NULL)) { SCReturnPtr(NULL, "DetectThresholdEntry"); } diff --git a/src/detect-engine.c b/src/detect-engine.c index 1db62a5b43..0f280cd86e 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -349,7 +349,7 @@ DetectEngineCtx *DetectEngineCtxInit(void) { char *insp_recursion_limit = NULL; de_ctx = SCMalloc(sizeof(DetectEngineCtx)); - if (de_ctx == NULL) + if (unlikely(de_ctx == NULL)) goto error; memset(de_ctx,0,sizeof(DetectEngineCtx)); @@ -741,7 +741,7 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data) { return TM_ECODE_FAILED; DetectEngineThreadCtx *det_ctx = SCMalloc(sizeof(DetectEngineThreadCtx)); - if (det_ctx == NULL) + if (unlikely(det_ctx == NULL)) return TM_ECODE_FAILED; memset(det_ctx, 0, sizeof(DetectEngineThreadCtx)); @@ -828,7 +828,7 @@ static TmEcode DetectEngineThreadCtxInitForLiveRuleSwap(ThreadVars *tv, void *in return TM_ECODE_FAILED; DetectEngineThreadCtx *det_ctx = SCMalloc(sizeof(DetectEngineThreadCtx)); - if (det_ctx == NULL) + if (unlikely(det_ctx == NULL)) return TM_ECODE_FAILED; memset(det_ctx, 0, sizeof(DetectEngineThreadCtx)); @@ -981,7 +981,7 @@ int DetectRegisterThreadCtxFuncs(DetectEngineCtx *de_ctx, const char *name, void BUG_ON(de_ctx == NULL || InitFunc == NULL || FreeFunc == NULL || data == NULL); DetectEngineThreadKeywordCtxItem *item = SCMalloc(sizeof(DetectEngineThreadKeywordCtxItem)); - if (item == NULL) + if (unlikely(item == NULL)) return -1; memset(item, 0x00, sizeof(DetectEngineThreadKeywordCtxItem)); diff --git a/src/detect-fast-pattern.c b/src/detect-fast-pattern.c index 994cd20ae8..1a9781aae5 100644 --- a/src/detect-fast-pattern.c +++ b/src/detect-fast-pattern.c @@ -67,7 +67,7 @@ static void SupportFastPatternForSigMatchList(int list_id) } SCFPSupportSMList *new_smlist_fp = SCMalloc(sizeof(SCFPSupportSMList)); - if (new_smlist_fp == NULL) { + if (unlikely(new_smlist_fp == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } diff --git a/src/detect-fileext.c b/src/detect-fileext.c index 520f60881c..80a5cef53a 100644 --- a/src/detect-fileext.c +++ b/src/detect-fileext.c @@ -139,7 +139,7 @@ static DetectFileextData *DetectFileextParse (char *str) /* We have a correct filename option */ fileext = SCMalloc(sizeof(DetectFileextData)); - if (fileext == NULL) + if (unlikely(fileext == NULL)) goto error; memset(fileext, 0x00, sizeof(DetectFileextData)); diff --git a/src/detect-filemagic.c b/src/detect-filemagic.c index ed2e78fa53..3100308bff 100644 --- a/src/detect-filemagic.c +++ b/src/detect-filemagic.c @@ -201,7 +201,7 @@ static DetectFilemagicData *DetectFilemagicParse (char *str) /* We have a correct filemagic option */ filemagic = SCMalloc(sizeof(DetectFilemagicData)); - if (filemagic == NULL) + if (unlikely(filemagic == NULL)) goto error; memset(filemagic, 0x00, sizeof(DetectFilemagicData)); diff --git a/src/detect-filemd5.c b/src/detect-filemd5.c index 6ceece9b9e..27c9ee3d1f 100644 --- a/src/detect-filemd5.c +++ b/src/detect-filemd5.c @@ -218,7 +218,7 @@ static DetectFileMd5Data *DetectFileMd5Parse (char *str) /* We have a correct filemd5 option */ filemd5 = SCMalloc(sizeof(DetectFileMd5Data)); - if (filemd5 == NULL) + if (unlikely(filemd5 == NULL)) goto error; memset(filemd5, 0x00, sizeof(DetectFileMd5Data)); diff --git a/src/detect-filename.c b/src/detect-filename.c index 2940f17c01..31fc0b6c6c 100644 --- a/src/detect-filename.c +++ b/src/detect-filename.c @@ -144,7 +144,7 @@ static DetectFilenameData *DetectFilenameParse (char *str) /* We have a correct filename option */ filename = SCMalloc(sizeof(DetectFilenameData)); - if (filename == NULL) + if (unlikely(filename == NULL)) goto error; memset(filename, 0x00, sizeof(DetectFilenameData)); diff --git a/src/detect-filesize.c b/src/detect-filesize.c index 1b7c77cee9..a56c8a0688 100644 --- a/src/detect-filesize.c +++ b/src/detect-filesize.c @@ -211,8 +211,8 @@ static DetectFilesizeData *DetectFilesizeParse (char *str) } fsd = SCMalloc(sizeof (DetectFilesizeData)); - if (fsd == NULL) - goto error; + if (unlikely(fsd == NULL)) + goto error; memset(fsd, 0, sizeof(DetectFilesizeData)); if (arg1[0] == '<') diff --git a/src/detect-filestore.c b/src/detect-filestore.c index d39cf08eae..535e22d44c 100644 --- a/src/detect-filestore.c +++ b/src/detect-filestore.c @@ -354,7 +354,7 @@ static int DetectFilestoreSetup (DetectEngineCtx *de_ctx, Signature *s, char *st } fd = SCMalloc(sizeof(DetectFilestoreData)); - if (fd == NULL) + if (unlikely(fd == NULL)) goto error; memset(fd, 0x00, sizeof(DetectFilestoreData)); diff --git a/src/detect-flags.c b/src/detect-flags.c index f5ae3141f0..f47f5cd955 100644 --- a/src/detect-flags.c +++ b/src/detect-flags.c @@ -206,7 +206,7 @@ static DetectFlagsData *DetectFlagsParse (char *rawstr) } de = SCMalloc(sizeof(DetectFlagsData)); - if (de == NULL) + if (unlikely(de == NULL)) goto error; memset(de,0,sizeof(DetectFlagsData)); @@ -567,7 +567,7 @@ static int FlagsTestParse02 (void) { */ static int FlagsTestParse03 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -622,7 +622,7 @@ error: */ static int FlagsTestParse04 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -677,7 +677,7 @@ error: */ static int FlagsTestParse05 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -732,7 +732,7 @@ error: */ static int FlagsTestParse06 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -787,7 +787,7 @@ error: */ static int FlagsTestParse07 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -842,7 +842,7 @@ error: */ static int FlagsTestParse08 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -897,7 +897,7 @@ error: */ static int FlagsTestParse09 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -952,7 +952,7 @@ error: */ static int FlagsTestParse10 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -1007,7 +1007,7 @@ error: */ static int FlagsTestParse11 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -1062,7 +1062,7 @@ error: */ static int FlagsTestParse12 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -1148,7 +1148,7 @@ static int FlagsTestParse14(void) static int FlagsTestParse15(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -1202,7 +1202,7 @@ error: static int FlagsTestParse16(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -1259,7 +1259,7 @@ error: static int FlagsTestParse17(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; diff --git a/src/detect-flow.c b/src/detect-flow.c index d437421d52..a22659663e 100644 --- a/src/detect-flow.c +++ b/src/detect-flow.c @@ -199,7 +199,7 @@ DetectFlowData *DetectFlowParse (char *flowstr) } fd = SCMalloc(sizeof(DetectFlowData)); - if (fd == NULL) + if (unlikely(fd == NULL)) goto error; fd->flags = 0; fd->match_cnt = 0; diff --git a/src/detect-flowbits.c b/src/detect-flowbits.c index 30c13497f9..9d97bab2f0 100644 --- a/src/detect-flowbits.c +++ b/src/detect-flowbits.c @@ -226,7 +226,7 @@ int DetectFlowbitSetup (DetectEngineCtx *de_ctx, Signature *s, char *rawstr) } cd = SCMalloc(sizeof(DetectFlowbitsData)); - if (cd == NULL) + if (unlikely(cd == NULL)) goto error; cd->idx = VariableNameGetIdx(de_ctx, fb_name, DETECT_FLOWBITS); @@ -306,7 +306,7 @@ static int FlowBitsTestSig01(void) { "\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -381,7 +381,7 @@ static int FlowBitsTestSig02(void) { "\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -503,7 +503,7 @@ static int FlowBitsTestSig03(void) { "\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -581,7 +581,7 @@ static int FlowBitsTestSig04(void) { "\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -663,7 +663,7 @@ static int FlowBitsTestSig05(void) { "\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -742,7 +742,7 @@ static int FlowBitsTestSig06(void) { "\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -846,7 +846,7 @@ static int FlowBitsTestSig07(void) { "\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -953,7 +953,7 @@ static int FlowBitsTestSig08(void) { "\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; diff --git a/src/detect-flowint.c b/src/detect-flowint.c index 2798c272e8..61b6f984bf 100644 --- a/src/detect-flowint.c +++ b/src/detect-flowint.c @@ -291,7 +291,7 @@ DetectFlowintData *DetectFlowintParse(DetectEngineCtx *de_ctx, } sfd = SCMalloc(sizeof(DetectFlowintData)); - if (sfd == NULL) + if (unlikely(sfd == NULL)) goto error; /* If we need another arg, check it out(isset doesn't need another arg) */ @@ -311,7 +311,7 @@ DetectFlowintData *DetectFlowintParse(DetectEngineCtx *de_ctx, /* get the target value to operate with *(it should be a value or another var) */ str = SCStrdup(varval); - if (str == NULL) { + if (unlikely(str == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "malloc from strdup failed"); goto error; } @@ -1322,7 +1322,7 @@ int DetectFlowintTestPacket01Real() }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; ThreadVars th_v; @@ -1656,7 +1656,7 @@ int DetectFlowintTestPacket02Real() }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; @@ -1994,7 +1994,7 @@ int DetectFlowintTestPacket03Real() }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; diff --git a/src/detect-flowvar.c b/src/detect-flowvar.c index ed7e7de135..744376817e 100644 --- a/src/detect-flowvar.c +++ b/src/detect-flowvar.c @@ -140,7 +140,7 @@ static int DetectFlowvarSetup (DetectEngineCtx *de_ctx, Signature *s, char *raws if (varcontent[0] == '\"' && varcontent[strlen(varcontent)-1] == '\"') { str = SCStrdup(varcontent+1); - if (str == NULL) { + if (unlikely(str == NULL)) { return -1; } str[strlen(varcontent)-2] = '\0'; @@ -154,7 +154,7 @@ static int DetectFlowvarSetup (DetectEngineCtx *de_ctx, Signature *s, char *raws } cd = SCMalloc(sizeof(DetectFlowvarData)); - if (cd == NULL) + if (unlikely(cd == NULL)) goto error; char converted = 0; diff --git a/src/detect-fragbits.c b/src/detect-fragbits.c index 127d61d58b..e61f0b45ef 100644 --- a/src/detect-fragbits.c +++ b/src/detect-fragbits.c @@ -193,7 +193,7 @@ static DetectFragBitsData *DetectFragBitsParse (char *rawstr) } de = SCMalloc(sizeof(DetectFragBitsData)); - if (de == NULL) + if (unlikely(de == NULL)) goto error; memset(de,0,sizeof(DetectFragBitsData)); @@ -403,7 +403,7 @@ static int FragBitsTestParse03 (void) { 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x0b, 0x51}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -500,7 +500,7 @@ static int FragBitsTestParse04 (void) { 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x0b, 0x51}; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/detect-fragoffset.c b/src/detect-fragoffset.c index 785bed841b..3d6f528959 100644 --- a/src/detect-fragoffset.c +++ b/src/detect-fragoffset.c @@ -159,7 +159,7 @@ DetectFragOffsetData *DetectFragOffsetParse (char *fragoffsetstr) { } fragoff = SCMalloc(sizeof(DetectFragOffsetData)); - if (fragoff == NULL) + if (unlikely(fragoff == NULL)) goto error; fragoff->frag_off = 0; @@ -302,7 +302,7 @@ int DetectFragOffsetParseTest03 (void) { int DetectFragOffsetMatchTest01 (void) { int result = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; DecodeThreadVars dtv; diff --git a/src/detect-ftpbounce.c b/src/detect-ftpbounce.c index e53bcdebae..80379bc317 100644 --- a/src/detect-ftpbounce.c +++ b/src/detect-ftpbounce.c @@ -448,7 +448,7 @@ static int DetectFtpbounceTestALMatch03(void) { TcpSession ssn; Flow f; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; diff --git a/src/detect-icmp-id.c b/src/detect-icmp-id.c index 4ff1792d61..62f977e1e2 100644 --- a/src/detect-icmp-id.c +++ b/src/detect-icmp-id.c @@ -170,7 +170,7 @@ DetectIcmpIdData *DetectIcmpIdParse (char *icmpidstr) { } iid = SCMalloc(sizeof(DetectIcmpIdData)); - if (iid == NULL) + if (unlikely(iid == NULL)) goto error; iid->id = 0; @@ -407,7 +407,7 @@ int DetectIcmpIdMatchTest02 (void) { 0x00, 0x14, 0x00, 0x00 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; DecodeThreadVars dtv; diff --git a/src/detect-icmp-seq.c b/src/detect-icmp-seq.c index 548184bffa..34afe3bb64 100644 --- a/src/detect-icmp-seq.c +++ b/src/detect-icmp-seq.c @@ -170,7 +170,7 @@ DetectIcmpSeqData *DetectIcmpSeqParse (char *icmpseqstr) { } iseq = SCMalloc(sizeof(DetectIcmpSeqData)); - if (iseq == NULL) + if (unlikely(iseq == NULL)) goto error; iseq->seq = 0; diff --git a/src/detect-icode.c b/src/detect-icode.c index 1a3362405d..9a3112c865 100644 --- a/src/detect-icode.c +++ b/src/detect-icode.c @@ -163,7 +163,7 @@ DetectICodeData *DetectICodeParse(char *icodestr) { } icd = SCMalloc(sizeof(DetectICodeData)); - if (icd == NULL) + if (unlikely(icd == NULL)) goto error; icd->code1 = 0; icd->code2 = 0; diff --git a/src/detect-id.c b/src/detect-id.c index a7973b15fb..38005083ea 100644 --- a/src/detect-id.c +++ b/src/detect-id.c @@ -161,11 +161,11 @@ DetectIdData *DetectIdParse (char *idstr) /* We have a correct id option */ id_d = SCMalloc(sizeof(DetectIdData)); - if (id_d == NULL) + if (unlikely(id_d == NULL)) goto error; orig = SCStrdup((char*)str_ptr); - if (orig == NULL) { + if (unlikely(orig == NULL)) { goto error; } tmp_str=orig; diff --git a/src/detect-ipopts.c b/src/detect-ipopts.c index b6c7384418..a59aa377cb 100644 --- a/src/detect-ipopts.c +++ b/src/detect-ipopts.c @@ -161,7 +161,7 @@ DetectIpOptsData *DetectIpOptsParse (char *rawstr) goto error; de = SCMalloc(sizeof(DetectIpOptsData)); - if (de == NULL) + if (unlikely(de == NULL)) goto error; de->ipopt = DIpOpts[i].code; @@ -269,7 +269,7 @@ int IpOptsTestParse02 (void) { */ int IpOptsTestParse03 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; @@ -321,7 +321,7 @@ error: */ int IpOptsTestParse04 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; int ret = 0; diff --git a/src/detect-ipproto.c b/src/detect-ipproto.c index 419f2d67ba..11e5f5a3e9 100644 --- a/src/detect-ipproto.c +++ b/src/detect-ipproto.c @@ -129,7 +129,7 @@ static DetectIPProtoData *DetectIPProtoParse(const char *optstr) /* Initialize the data */ data = SCMalloc(sizeof(DetectIPProtoData)); - if (data == NULL) + if (unlikely(data == NULL)) goto error; data->op = DETECT_IPPROTO_OP_EQ; data->proto = 0; @@ -8867,7 +8867,7 @@ static int DetectIPProtoTestSig2(void) }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); diff --git a/src/detect-isdataat.c b/src/detect-isdataat.c index ba4773693f..2a4f59aee0 100644 --- a/src/detect-isdataat.c +++ b/src/detect-isdataat.c @@ -176,7 +176,7 @@ DetectIsdataatData *DetectIsdataatParse (char *isdataatstr, char **offset) } idad = SCMalloc(sizeof(DetectIsdataatData)); - if (idad == NULL) + if (unlikely(idad == NULL)) goto error; idad->flags = 0; diff --git a/src/detect-itype.c b/src/detect-itype.c index 7941ebbd96..f59cd1a3eb 100644 --- a/src/detect-itype.c +++ b/src/detect-itype.c @@ -163,7 +163,7 @@ DetectITypeData *DetectITypeParse(char *itypestr) { } itd = SCMalloc(sizeof(DetectITypeData)); - if (itd == NULL) + if (unlikely(itd == NULL)) goto error; itd->type1 = 0; itd->type2 = 0; diff --git a/src/detect-l3proto.c b/src/detect-l3proto.c index 1432913030..cb208e04a1 100644 --- a/src/detect-l3proto.c +++ b/src/detect-l3proto.c @@ -76,7 +76,7 @@ static int DetectL3ProtoSetup(DetectEngineCtx *de_ctx, Signature *s, char *optst /* strip "'s */ if (optstr[0] == '\"' && optstr[strlen(optstr) - 1] == '\"') { str = SCStrdup(optstr + 1); - if (str == NULL) + if (unlikely(str == NULL)) goto error; str[strlen(optstr) - 2] = '\0'; dubbed = 1; @@ -133,7 +133,7 @@ error: static int DetectL3protoTestSig1(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -218,7 +218,7 @@ end: static int DetectL3protoTestSig2(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; @@ -302,7 +302,7 @@ end: static int DetectL3protoTestSig3(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; diff --git a/src/detect-luajit.c b/src/detect-luajit.c index 572d4ba77d..64ec14ed88 100644 --- a/src/detect-luajit.c +++ b/src/detect-luajit.c @@ -461,7 +461,7 @@ static void *DetectLuajitThreadInit(void *data) { BUG_ON(luajit == NULL); DetectLuajitThreadData *t = SCMalloc(sizeof(DetectLuajitThreadData)); - if (t == NULL) { + if (unlikely(t == NULL)) { SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't alloc ctx memory"); return NULL; } @@ -522,7 +522,7 @@ static DetectLuajitData *DetectLuajitParse (char *str) /* We have a correct luajit option */ luajit = SCMalloc(sizeof(DetectLuajitData)); - if (luajit == NULL) + if (unlikely(luajit == NULL)) goto error; memset(luajit, 0x00, sizeof(DetectLuajitData)); diff --git a/src/detect-mark.c b/src/detect-mark.c index 0e24e10fc1..926c1a6e9a 100644 --- a/src/detect-mark.c +++ b/src/detect-mark.c @@ -148,7 +148,7 @@ static void * DetectMarkParse (char *rawstr) if (ptr == NULL) { data = SCMalloc(sizeof(DetectMarkData)); - if (data == NULL) { + if (unlikely(data == NULL)) { return NULL; } data->mark = mark; @@ -179,7 +179,7 @@ static void * DetectMarkParse (char *rawstr) SCFree(ptr); data = SCMalloc(sizeof(DetectMarkData)); - if (data == NULL) { + if (unlikely(data == NULL)) { return NULL; } data->mark = mark; diff --git a/src/detect-msg.c b/src/detect-msg.c index c3254fc79b..4bcd65d83d 100644 --- a/src/detect-msg.c +++ b/src/detect-msg.c @@ -55,13 +55,13 @@ static int DetectMsgSetup (DetectEngineCtx *de_ctx, Signature *s, char *msgstr) /* strip "'s */ if (msgstr[0] == '\"' && msgstr[strlen(msgstr)-1] == '\"') { str = SCStrdup(msgstr+1); - if (str == NULL) + if (unlikely(str == NULL)) goto error; str[strlen(msgstr)-2] = '\0'; } else if (msgstr[1] == '\"' && msgstr[strlen(msgstr)-1] == '\"') { /* XXX do this parsing in a better way */ str = SCStrdup(msgstr+2); - if (str == NULL) + if (unlikely(str == NULL)) goto error; str[strlen(msgstr)-3] = '\0'; //printf("DetectMsgSetup: format hack applied: \'%s\'\n", str); diff --git a/src/detect-offset.c b/src/detect-offset.c index d331b0a579..e5412d7a35 100644 --- a/src/detect-offset.c +++ b/src/detect-offset.c @@ -60,7 +60,7 @@ int DetectOffsetSetup (DetectEngineCtx *de_ctx, Signature *s, char *offsetstr) /* strip "'s */ if (offsetstr[0] == '\"' && offsetstr[strlen(offsetstr)-1] == '\"') { str = SCStrdup(offsetstr+1); - if (str == NULL) + if (unlikely(str == NULL)) goto error; str[strlen(offsetstr)-2] = '\0'; dubbed = 1; diff --git a/src/detect-parse.c b/src/detect-parse.c index 19ac780a9d..a52176e2db 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -105,7 +105,7 @@ uint32_t DbgGetDstPortAnyCnt(void) { SigMatch *SigMatchAlloc(void) { SigMatch *sm = SCMalloc(sizeof(SigMatch)); - if (sm == NULL) + if (unlikely(sm == NULL)) return NULL; memset(sm, 0, sizeof(SigMatch)); @@ -369,8 +369,8 @@ static int SigParseOptions(DetectEngineCtx *de_ctx, Signature *s, char *optstr) char *optname = NULL, *optvalue = NULL, *optmore = NULL; const char **arr = SCCalloc(OPTION_PARTS+1, sizeof(char *)); - if (arr == NULL) - return -1; + if (unlikely(arr == NULL)) + return -1; ret = pcre_exec(option_pcre, option_pcre_extra, optstr, strlen(optstr), 0, 0, ov, MAX_SUBSTRINGS); /* if successful, we either have: @@ -653,8 +653,8 @@ static int SigParseBasics(Signature *s, char *sigstr, char ***result, uint8_t ad int ret = 0, i = 0; const char **arr = SCCalloc(CONFIG_PARTS + 1, sizeof(char *)); - if (arr == NULL) - return -1; + if (unlikely(arr == NULL)) + return -1; ret = pcre_exec(config_pcre, config_pcre_extra, sigstr, strlen(sigstr), 0, 0, ov, MAX_SUBSTRINGS); if (ret != 8 && ret != 9) { @@ -784,7 +784,7 @@ int SigParse(DetectEngineCtx *de_ctx, Signature *s, char *sigstr, uint8_t addrs_ Signature *SigAlloc (void) { Signature *sig = SCMalloc(sizeof(Signature)); - if (sig == NULL) + if (unlikely(sig == NULL)) return NULL; memset(sig, 0, sizeof(Signature)); @@ -1467,7 +1467,7 @@ static inline int DetectEngineSignatureIsDuplicate(DetectEngineCtx *de_ctx, /* used for making a duplicate_sig_hash_table entry */ sw = SCMalloc(sizeof(SigDuplWrapper)); - if (sw == NULL) { + if (unlikely(sw == NULL)) { exit(EXIT_FAILURE); } memset(sw, 0, sizeof(SigDuplWrapper)); @@ -1794,7 +1794,7 @@ int DetectParseContentString (char *contentstr, uint8_t **result, uint16_t *resu } content = SCMalloc(len); - if (content == NULL) { + if (unlikely(content == NULL)) { exit(EXIT_FAILURE); } @@ -2786,7 +2786,7 @@ int SigTestBidirec04 (void) { 0x76,0x65,0x0d,0x0a,0x0d,0x0a }; /* end rawpkt1_ether */ p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; ThreadVars th_v; diff --git a/src/detect-pcre.c b/src/detect-pcre.c index e12880efa2..a0c51e34a7 100644 --- a/src/detect-pcre.c +++ b/src/detect-pcre.c @@ -309,7 +309,7 @@ DetectPcreData *DetectPcreParse (DetectEngineCtx *de_ctx, char *regexstr) //printf("ret %" PRId32 " re \'%s\', op \'%s\'\n", ret, re, op); pd = SCMalloc(sizeof(DetectPcreData)); - if (pd == NULL) + if (unlikely(pd == NULL)) goto error; memset(pd, 0, sizeof(DetectPcreData)); diff --git a/src/detect-pktvar.c b/src/detect-pktvar.c index 6973ede5a7..fb14f68bdf 100644 --- a/src/detect-pktvar.c +++ b/src/detect-pktvar.c @@ -136,7 +136,7 @@ static int DetectPktvarSetup (DetectEngineCtx *de_ctx, Signature *s, char *rawst if (varcontent[0] == '\"' && varcontent[strlen(varcontent)-1] == '\"') { str = SCStrdup(varcontent+1); - if (str == NULL) { + if (unlikely(str == NULL)) { return -1; } str[strlen(varcontent)-2] = '\0'; @@ -150,7 +150,7 @@ static int DetectPktvarSetup (DetectEngineCtx *de_ctx, Signature *s, char *rawst } cd = SCMalloc(sizeof(DetectPktvarData)); - if (cd == NULL) + if (unlikely(cd == NULL)) goto error; char converted = 0; diff --git a/src/detect-reference.c b/src/detect-reference.c index 2843241188..08303ebc36 100644 --- a/src/detect-reference.c +++ b/src/detect-reference.c @@ -128,7 +128,7 @@ static DetectReference *DetectReferenceParse(char *rawstr, DetectEngineCtx *de_c } ref = SCMalloc(sizeof(DetectReference)); - if (ref == NULL) { + if (unlikely(ref == NULL)) { goto error; } memset(ref, 0, sizeof(DetectReference)); diff --git a/src/detect-replace.c b/src/detect-replace.c index aa8fa06542..6b06875a0f 100644 --- a/src/detect-replace.c +++ b/src/detect-replace.c @@ -155,7 +155,7 @@ DetectReplaceList * DetectReplaceAddToList(DetectReplaceList *replist, uint8_t * SCLogDebug("replace: Adding match"); newlist = SCMalloc(sizeof(DetectReplaceList)); - if (newlist == NULL) + if (unlikely(newlist == NULL)) return NULL; newlist->found = found; newlist->cd = cd; @@ -218,7 +218,7 @@ int DetectReplaceLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize, ch Packet *p = NULL; p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; diff --git a/src/detect-rev.c b/src/detect-rev.c index 9d56735907..74cc5a77ad 100644 --- a/src/detect-rev.c +++ b/src/detect-rev.c @@ -46,7 +46,7 @@ static int DetectRevSetup (DetectEngineCtx *de_ctx, Signature *s, char *rawstr) /* strip "'s */ if (rawstr[0] == '\"' && rawstr[strlen(rawstr)-1] == '\"') { str = SCStrdup(rawstr+1); - if (str == NULL) + if (unlikely(str == NULL)) return -1; str[strlen(rawstr)-2] = '\0'; diff --git a/src/detect-rpc.c b/src/detect-rpc.c index 6341c80efb..8e7d64be50 100644 --- a/src/detect-rpc.c +++ b/src/detect-rpc.c @@ -200,7 +200,7 @@ DetectRpcData *DetectRpcParse (char *rpcstr) } rd = SCMalloc(sizeof(DetectRpcData)); - if (rd == NULL) + if (unlikely(rd == NULL)) goto error; rd->flags = 0; rd->program = 0; diff --git a/src/detect-seq.c b/src/detect-seq.c index 064782c1b2..d757a450dd 100644 --- a/src/detect-seq.c +++ b/src/detect-seq.c @@ -96,7 +96,7 @@ static int DetectSeqSetup (DetectEngineCtx *de_ctx, Signature *s, char *optstr) SigMatch *sm = NULL; data = SCMalloc(sizeof(DetectSeqData)); - if (data == NULL) + if (unlikely(data == NULL)) goto error; sm = SigMatchAlloc(); diff --git a/src/detect-sid.c b/src/detect-sid.c index 7af28709e9..d67c1282fd 100644 --- a/src/detect-sid.c +++ b/src/detect-sid.c @@ -46,7 +46,7 @@ static int DetectSidSetup (DetectEngineCtx *de_ctx, Signature *s, char *sidstr) /* strip "'s */ if (sidstr[0] == '\"' && sidstr[strlen(sidstr)-1] == '\"') { str = SCStrdup(sidstr+1); - if (str == NULL) + if (unlikely(str == NULL)) return -1; str[strlen(sidstr)-2] = '\0'; diff --git a/src/detect-ssh-proto-version.c b/src/detect-ssh-proto-version.c index 474959a088..e6e180d940 100644 --- a/src/detect-ssh-proto-version.c +++ b/src/detect-ssh-proto-version.c @@ -187,7 +187,7 @@ DetectSshVersionData *DetectSshVersionParse (char *str) /* We have a correct id option */ ssh = SCMalloc(sizeof(DetectSshVersionData)); - if (ssh == NULL) + if (unlikely(ssh == NULL)) goto error; memset(ssh, 0x00, sizeof(DetectSshVersionData)); diff --git a/src/detect-ssh-software-version.c b/src/detect-ssh-software-version.c index 3161bdcbfc..d39aaecc0e 100644 --- a/src/detect-ssh-software-version.c +++ b/src/detect-ssh-software-version.c @@ -176,7 +176,7 @@ DetectSshSoftwareVersionData *DetectSshSoftwareVersionParse (char *str) /* We have a correct id option */ ssh = SCMalloc(sizeof(DetectSshSoftwareVersionData)); - if (ssh == NULL) + if (unlikely(ssh == NULL)) goto error; ssh->software_ver = (uint8_t *)SCStrdup((char*)str_ptr); diff --git a/src/detect-ssl-version.c b/src/detect-ssl-version.c index 186769f5d3..5298f509e9 100644 --- a/src/detect-ssl-version.c +++ b/src/detect-ssl-version.c @@ -210,7 +210,7 @@ DetectSslVersionData *DetectSslVersionParse(char *str) /* We have a correct ssl_version options */ ssl = SCCalloc(1, sizeof (DetectSslVersionData)); - if (ssl == NULL) + if (unlikely(ssl == NULL)) goto error; int i; @@ -224,7 +224,7 @@ DetectSslVersionData *DetectSslVersionParse(char *str) } orig = SCStrdup((char*) str_ptr[i]); - if (orig == NULL) { + if (unlikely(orig == NULL)) { goto error; } tmp_str = orig; diff --git a/src/detect-stream_size.c b/src/detect-stream_size.c index be7f39528b..2866d621f2 100644 --- a/src/detect-stream_size.c +++ b/src/detect-stream_size.c @@ -231,8 +231,8 @@ DetectStreamSizeData *DetectStreamSizeParse (char *streamstr) { value = (char *)str_ptr; sd = SCMalloc(sizeof(DetectStreamSizeData)); - if (sd == NULL) - goto error; + if (unlikely(sd == NULL)) + goto error; sd->ssize = 0; sd->flags = 0; @@ -386,7 +386,7 @@ static int DetectStreamSizeParseTest03 (void) { ThreadVars tv; DetectEngineThreadCtx dtx; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature s; SigMatch sm; @@ -463,7 +463,7 @@ static int DetectStreamSizeParseTest04 (void) { ThreadVars tv; DetectEngineThreadCtx dtx; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature s; SigMatch sm; diff --git a/src/detect-tag.c b/src/detect-tag.c index 1715eafef8..9d7d8590b8 100644 --- a/src/detect-tag.c +++ b/src/detect-tag.c @@ -271,7 +271,7 @@ DetectTagData *DetectTagParse (char *tagstr) } DetectTagData *real_td = SCMalloc(sizeof(DetectTagData)); - if (real_td == NULL) { + if (unlikely(real_td == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); goto error; } diff --git a/src/detect-threshold.c b/src/detect-threshold.c index 035ee71a57..8074f37020 100644 --- a/src/detect-threshold.c +++ b/src/detect-threshold.c @@ -132,7 +132,7 @@ static DetectThresholdData *DetectThresholdParse (char *rawstr) int i = 0; copy_str = SCStrdup(rawstr); - if (copy_str == NULL) { + if (unlikely(copy_str == NULL)) { goto error; } @@ -164,7 +164,7 @@ static DetectThresholdData *DetectThresholdParse (char *rawstr) } de = SCMalloc(sizeof(DetectThresholdData)); - if (de == NULL) + if (unlikely(de == NULL)) goto error; memset(de,0,sizeof(DetectThresholdData)); diff --git a/src/detect-tls-version.c b/src/detect-tls-version.c index f4435c3e97..ffad7c945d 100644 --- a/src/detect-tls-version.c +++ b/src/detect-tls-version.c @@ -175,11 +175,11 @@ DetectTlsVersionData *DetectTlsVersionParse (char *str) /* We have a correct id option */ tls = SCMalloc(sizeof(DetectTlsVersionData)); - if (tls == NULL) + if (unlikely(tls == NULL)) goto error; orig = SCStrdup((char*)str_ptr); - if (orig == NULL) { + if (unlikely(orig == NULL)) { goto error; } tmp_str=orig; diff --git a/src/detect-tls.c b/src/detect-tls.c index ae48b3607b..5f4b7835ab 100644 --- a/src/detect-tls.c +++ b/src/detect-tls.c @@ -278,13 +278,13 @@ static DetectTlsData *DetectTlsSubjectParse (char *str) /* We have a correct id option */ tls = SCMalloc(sizeof(DetectTlsData)); - if (tls == NULL) + if (unlikely(tls == NULL)) goto error; tls->subject = NULL; tls->flags = flag; orig = SCStrdup((char*)str_ptr); - if (orig == NULL) { + if (unlikely(orig == NULL)) { goto error; } tmp_str=orig; @@ -477,13 +477,13 @@ static DetectTlsData *DetectTlsIssuerDNParse(char *str) /* We have a correct id option */ tls = SCMalloc(sizeof(DetectTlsData)); - if (tls == NULL) + if (unlikely(tls == NULL)) goto error; tls->issuerdn = NULL; tls->flags = flag; orig = SCStrdup((char*)str_ptr); - if (orig == NULL) { + if (unlikely(orig == NULL)) { goto error; } tmp_str=orig; @@ -613,13 +613,13 @@ static DetectTlsData *DetectTlsFingerprintParse (char *str) /* We have a correct id option */ tls = SCMalloc(sizeof(DetectTlsData)); - if (tls == NULL) + if (unlikely(tls == NULL)) goto error; tls->fingerprint = NULL; tls->flags = flag; orig = SCStrdup((char*)str_ptr); - if (orig == NULL) { + if (unlikely(orig == NULL)) { goto error; } tmp_str=orig; diff --git a/src/detect-tos.c b/src/detect-tos.c index aa4f9342e7..90d9e81433 100644 --- a/src/detect-tos.c +++ b/src/detect-tos.c @@ -175,7 +175,7 @@ DetectTosData *DetectTosParse(char *arg) } tosd = SCMalloc(sizeof(DetectTosData)); - if (tosd == NULL) + if (unlikely(tosd == NULL)) goto error; tosd->tos = (uint8_t)tos; tosd->negated = negated; diff --git a/src/detect-ttl.c b/src/detect-ttl.c index a83451bbc7..e2534e52c4 100644 --- a/src/detect-ttl.c +++ b/src/detect-ttl.c @@ -177,8 +177,8 @@ DetectTtlData *DetectTtlParse (char *ttlstr) { } ttld = SCMalloc(sizeof (DetectTtlData)); - if (ttld == NULL) - goto error; + if (unlikely(ttld == NULL)) + goto error; ttld->ttl1 = 0; ttld->ttl2 = 0; @@ -524,7 +524,7 @@ end: static int DetectTtlTestSig1(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Signature *s = NULL; ThreadVars th_v; diff --git a/src/detect-uricontent.c b/src/detect-uricontent.c index 5fa4040faf..e1d258b1b0 100644 --- a/src/detect-uricontent.c +++ b/src/detect-uricontent.c @@ -118,7 +118,7 @@ void DetectUricontentPrint(DetectContentData *cd) return; } char *tmpstr = SCMalloc(sizeof(char) * cd->content_len + 1); - if (tmpstr == NULL) + if (unlikely(tmpstr == NULL)) return; if (tmpstr != NULL) { @@ -170,7 +170,7 @@ DetectContentData *DoDetectUricontentSetup (char *contentstr) } cd = SCMalloc(sizeof(DetectContentData) + len); - if (cd == NULL) { + if (unlikely(cd == NULL)) { SCFree(str); exit(EXIT_FAILURE); } diff --git a/src/detect-urilen.c b/src/detect-urilen.c index 937eefb3da..e8da8e25ee 100644 --- a/src/detect-urilen.c +++ b/src/detect-urilen.c @@ -237,8 +237,8 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr) } urilend = SCMalloc(sizeof (DetectUrilenData)); - if (urilend == NULL) - goto error; + if (unlikely(urilend == NULL)) + goto error; memset(urilend, 0, sizeof(DetectUrilenData)); if (arg1[0] == '<') diff --git a/src/detect-window.c b/src/detect-window.c index d9ce412d12..4d7c7c8988 100644 --- a/src/detect-window.c +++ b/src/detect-window.c @@ -140,7 +140,7 @@ DetectWindowData *DetectWindowParse(char *windowstr) { } wd = SCMalloc(sizeof(DetectWindowData)); - if (wd == NULL) + if (unlikely(wd == NULL)) goto error; if (ret > 1) { diff --git a/src/detect-within.c b/src/detect-within.c index 94a391f087..a267c3c85a 100644 --- a/src/detect-within.c +++ b/src/detect-within.c @@ -72,7 +72,7 @@ static int DetectWithinSetup (DetectEngineCtx *de_ctx, Signature *s, char *withi /* strip "'s */ if (withinstr[0] == '\"' && withinstr[strlen(withinstr)-1] == '\"') { str = SCStrdup(withinstr+1); - if (str == NULL) + if (unlikely(str == NULL)) goto error; str[strlen(withinstr)-2] = '\0'; dubbed = 1; diff --git a/src/detect.c b/src/detect.c index 0f64639731..20e8bbda52 100644 --- a/src/detect.c +++ b/src/detect.c @@ -244,7 +244,7 @@ char *DetectLoadCompleteSigPath(char *sig_file) size_t path_len = sizeof(char) * (strlen(defaultpath) + strlen(sig_file) + 2); path = SCMalloc(path_len); - if (path == NULL) + if (unlikely(path == NULL)) return NULL; strlcpy(path, defaultpath, path_len); #if defined OS_WIN32 || defined __CYGWIN__ @@ -257,12 +257,12 @@ char *DetectLoadCompleteSigPath(char *sig_file) strlcat(path, sig_file, path_len); } else { path = SCStrdup(sig_file); - if (path == NULL) + if (unlikely(path == NULL)) return NULL; } } else { path = SCStrdup(sig_file); - if (path == NULL) + if (unlikely(path == NULL)) return NULL; } return path; @@ -333,7 +333,7 @@ static inline void EngineAnalysisWriteFastPattern(Signature *s, SigMatch *mpm_sm uint16_t patlen = fp_cd->content_len; uint8_t *pat = SCMalloc(fp_cd->content_len + 1); - if (pat == NULL) { + if (unlikely(pat == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -347,7 +347,7 @@ static inline void EngineAnalysisWriteFastPattern(Signature *s, SigMatch *mpm_sm SCFree(pat); patlen = fp_cd->fp_chop_len; pat = SCMalloc(fp_cd->fp_chop_len + 1); - if (pat == NULL) { + if (unlikely(pat == NULL)) { exit(EXIT_FAILURE); } memcpy(pat, fp_cd->content + fp_cd->fp_chop_offset, fp_cd->fp_chop_len); @@ -5894,7 +5894,7 @@ static int SigTest15Real (int mpm_type) { "CONNECT 213.92.8.7:31204 HTTP/1.1"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx; @@ -6102,7 +6102,7 @@ static int SigTest18Real (int mpm_type) { "220 (vsFTPd 2.0.5)\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx; @@ -6166,7 +6166,7 @@ int SigTest19Real (int mpm_type) { "220 (vsFTPd 2.0.5)\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx; @@ -6237,7 +6237,7 @@ static int SigTest20Real (int mpm_type) { "220 (vsFTPd 2.0.5)\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx; @@ -6579,10 +6579,10 @@ int SigTest24IPV4Keyword(void) 0xc0, 0xa8, 0x01, 0x06}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -6685,10 +6685,10 @@ int SigTest25NegativeIPV4Keyword(void) 0xc0, 0xa8, 0x01, 0x06}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -6797,11 +6797,11 @@ int SigTest26TCPV4Keyword(void) 0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 0x03}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -6913,10 +6913,10 @@ static int SigTest27NegativeTCPV4Keyword(void) Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -7041,10 +7041,10 @@ int SigTest28TCPV6Keyword(void) 0x00, 0x01, 0x69, 0x28}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -7171,10 +7171,10 @@ int SigTest29NegativeTCPV6Keyword(void) 0x00, 0x01, 0x69, 0x28}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -7296,10 +7296,10 @@ int SigTest30UDPV4Keyword(void) 0x67, 0x6c, 0x65, 0xc0, 0x27}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -7421,10 +7421,10 @@ int SigTest31NegativeUDPV4Keyword(void) 0x67, 0x6c, 0x65, 0xc0, 0x27}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -7540,10 +7540,10 @@ int SigTest32UDPV6Keyword(void) 0x09, 0x01}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -7657,10 +7657,10 @@ int SigTest33NegativeUDPV6Keyword(void) 0x09, 0x01}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -7776,10 +7776,10 @@ int SigTest34ICMPV4Keyword(void) 0x34, 0x35, 0x36, 0x38}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -7898,10 +7898,10 @@ int SigTest35NegativeICMPV4Keyword(void) 0x34, 0x35, 0x36, 0x38}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -8031,10 +8031,10 @@ int SigTest36ICMPV6Keyword(void) 0x08, 0x01}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -8161,10 +8161,10 @@ int SigTest37NegativeICMPV6Keyword(void) 0x08, 0x01}; Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; Packet *p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) { + if (unlikely(p2 == NULL)) { SCFree(p1); return 0; } @@ -8255,7 +8255,7 @@ end: int SigTest38Real(int mpm_type) { Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx = NULL; @@ -8398,7 +8398,7 @@ static int SigTest38Wm (void) { int SigTest39Real(int mpm_type) { Packet *p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx = NULL; @@ -8587,7 +8587,7 @@ int SigTest36ContentAndIsdataatKeywords01Real (int mpm_type) { ,0x3e,0x3c,0x2f,0x48,0x54,0x4d,0x4c,0x3e,0x0d,0x0a }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; @@ -8705,7 +8705,7 @@ int SigTest37ContentAndIsdataatKeywords02Real (int mpm_type) { ,0x3e,0x3c,0x2f,0x48,0x54,0x4d,0x4c,0x3e,0x0d,0x0a }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DecodeThreadVars dtv; @@ -8826,7 +8826,7 @@ int SigTest40NoPacketInspection01(void) { uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); TCPHdr tcphdr; - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx; @@ -8901,7 +8901,7 @@ int SigTest40NoPayloadInspection02(void) { "220 (vsFTPd 2.0.5)\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx; @@ -8963,7 +8963,7 @@ static int SigTestMemory01 (void) { "\r\n\r\n"; uint16_t buflen = strlen((char *)buf); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars th_v; DetectEngineThreadCtx *det_ctx; @@ -9433,7 +9433,7 @@ static int SigTestSgh03 (void) { ThreadVars th_v; int result = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DetectEngineThreadCtx *det_ctx; @@ -9605,7 +9605,7 @@ static int SigTestSgh04 (void) { ThreadVars th_v; int result = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DetectEngineThreadCtx *det_ctx; @@ -9798,7 +9798,7 @@ static int SigTestSgh05 (void) { ThreadVars th_v; int result = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; DetectEngineThreadCtx *det_ctx; @@ -10348,7 +10348,7 @@ static int SigTestWithinReal01 (int mpm_type) { /* packet 1 */ p1 = SCMalloc(SIZE_OF_PACKET); - if (p1 == NULL) + if (unlikely(p1 == NULL)) return 0; memset(p1, 0, SIZE_OF_PACKET); p1->pkt = (uint8_t *)(p1 + 1); @@ -10361,7 +10361,7 @@ static int SigTestWithinReal01 (int mpm_type) { /* packet 2 */ p2 = SCMalloc(SIZE_OF_PACKET); - if (p2 == NULL) + if (unlikely(p2 == NULL)) return 0; memset(p2, 0, SIZE_OF_PACKET); p2->pkt = (uint8_t *)(p2 + 1); @@ -10374,7 +10374,7 @@ static int SigTestWithinReal01 (int mpm_type) { /* packet 3 */ p3 = SCMalloc(SIZE_OF_PACKET); - if (p3 == NULL) + if (unlikely(p3 == NULL)) return 0; memset(p3, 0, SIZE_OF_PACKET); p3->pkt = (uint8_t *)(p3 + 1); @@ -10387,7 +10387,7 @@ static int SigTestWithinReal01 (int mpm_type) { /* packet 4 */ p4 = SCMalloc(SIZE_OF_PACKET); - if (p4 == NULL) + if (unlikely(p4 == NULL)) return 0; memset(p4, 0, SIZE_OF_PACKET); p4->pkt = (uint8_t *)(p4 + 1); diff --git a/src/flow-alert-sid.c b/src/flow-alert-sid.c index 7ca2b42d8d..4dfc0a0c01 100644 --- a/src/flow-alert-sid.c +++ b/src/flow-alert-sid.c @@ -64,7 +64,7 @@ static void FlowAlertSidAdd(Flow *f, uint32_t sid) { FlowAlertSid *fb = FlowAlertSidGet(f, sid); if (fb == NULL) { fb = SCMalloc(sizeof(FlowAlertSid)); - if (fb == NULL) + if (unlikely(fb == NULL)) return; fb->type = DETECT_FLOWALERTSID; diff --git a/src/flow-bit.c b/src/flow-bit.c index 6bd62d7e87..be08c2bf79 100644 --- a/src/flow-bit.c +++ b/src/flow-bit.c @@ -59,7 +59,7 @@ static void FlowBitAdd(Flow *f, uint16_t idx) { FlowBit *fb = FlowBitGet(f, idx); if (fb == NULL) { fb = SCMalloc(sizeof(FlowBit)); - if (fb == NULL) + if (unlikely(fb == NULL)) return; fb->type = DETECT_FLOWBITS; diff --git a/src/flow-util.c b/src/flow-util.c index 44f3fa1a17..5b4b3a715d 100644 --- a/src/flow-util.c +++ b/src/flow-util.c @@ -56,8 +56,8 @@ Flow *FlowAlloc(void) (void) SC_ATOMIC_ADD(flow_memuse, sizeof(Flow)); f = SCMalloc(sizeof(Flow)); - if (f == NULL) { - (void) SC_ATOMIC_SUB(flow_memuse, sizeof(Flow)); + if (unlikely(f == NULL)) { + (void)SC_ATOMIC_SUB(flow_memuse, sizeof(Flow)); return NULL; } diff --git a/src/flow-var.c b/src/flow-var.c index 713d502248..26db5eb17d 100644 --- a/src/flow-var.c +++ b/src/flow-var.c @@ -67,7 +67,7 @@ void FlowVarAddStr(Flow *f, uint8_t idx, uint8_t *value, uint16_t size) { FlowVar *fv = FlowVarGet(f, idx); if (fv == NULL) { fv = SCMalloc(sizeof(FlowVar)); - if (fv == NULL) + if (unlikely(fv == NULL)) goto out; fv->type = DETECT_FLOWVAR; @@ -95,7 +95,7 @@ void FlowVarAddInt(Flow *f, uint8_t idx, uint32_t value) { FlowVar *fv = FlowVarGet(f, idx); if (fv == NULL) { fv = SCMalloc(sizeof(FlowVar)); - if (fv == NULL) + if (unlikely(fv == NULL)) goto out; fv->type = DETECT_FLOWVAR; diff --git a/src/flow.c b/src/flow.c index 5242d2f2d7..0a8462ce57 100644 --- a/src/flow.c +++ b/src/flow.c @@ -394,7 +394,7 @@ void FlowInitConfig(char quiet) exit(EXIT_FAILURE); } flow_hash = SCCalloc(flow_config.hash_size, sizeof(FlowBucket)); - if (flow_hash == NULL) { + if (unlikely(flow_hash == NULL)) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in FlowInitConfig. Exiting..."); exit(EXIT_FAILURE); } diff --git a/src/host.c b/src/host.c index 59cc09464b..f62d7dfb64 100644 --- a/src/host.c +++ b/src/host.c @@ -62,7 +62,7 @@ Host *HostAlloc(void) { (void) SC_ATOMIC_ADD(host_memuse, sizeof(Host)); Host *h = SCMalloc(sizeof(Host)); - if (h == NULL) + if (unlikely(h == NULL)) goto error; memset(h, 0x00, sizeof(Host)); @@ -181,7 +181,7 @@ void HostInitConfig(char quiet) exit(EXIT_FAILURE); } host_hash = SCCalloc(host_config.hash_size, sizeof(HostHashRow)); - if (host_hash == NULL) { + if (unlikely(host_hash == NULL)) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in HostInitConfig. Exiting..."); exit(EXIT_FAILURE); } diff --git a/src/log-droplog.c b/src/log-droplog.c index caac9640de..6f3edbaca1 100644 --- a/src/log-droplog.c +++ b/src/log-droplog.c @@ -106,7 +106,7 @@ TmEcode LogDropLogThreadInit(ThreadVars *t, void *initdata, void **data) } LogDropLogThread *dlt = SCMalloc(sizeof(LogDropLogThread)); - if (dlt == NULL) + if (unlikely(dlt == NULL)) return TM_ECODE_FAILED; memset(dlt, 0, sizeof(LogDropLogThread)); @@ -158,7 +158,7 @@ OutputCtx *LogDropLogInitCtx(ConfNode *conf) } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) { + if (unlikely(output_ctx == NULL)) { LogFileFreeCtx(logfile_ctx); return NULL; } diff --git a/src/log-file.c b/src/log-file.c index 52485fa0eb..5fa0e20c0e 100644 --- a/src/log-file.c +++ b/src/log-file.c @@ -363,7 +363,7 @@ TmEcode LogFileLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pack TmEcode LogFileLogThreadInit(ThreadVars *t, void *initdata, void **data) { LogFileLogThread *aft = SCMalloc(sizeof(LogFileLogThread)); - if (aft == NULL) + if (unlikely(aft == NULL)) return TM_ECODE_FAILED; memset(aft, 0, sizeof(LogFileLogThread)); @@ -422,7 +422,7 @@ static OutputCtx *LogFileLogInitCtx(ConfNode *conf) } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) + if (unlikely(output_ctx == NULL)) return NULL; output_ctx->data = logfile_ctx; diff --git a/src/log-filestore.c b/src/log-filestore.c index 15c893ae89..60e8111c29 100644 --- a/src/log-filestore.c +++ b/src/log-filestore.c @@ -424,7 +424,7 @@ TmEcode LogFilestoreLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, TmEcode LogFilestoreLogThreadInit(ThreadVars *t, void *initdata, void **data) { LogFilestoreLogThread *aft = SCMalloc(sizeof(LogFilestoreLogThread)); - if (aft == NULL) + if (unlikely(aft == NULL)) return TM_ECODE_FAILED; memset(aft, 0, sizeof(LogFilestoreLogThread)); @@ -539,7 +539,7 @@ static OutputCtx *LogFilestoreLogInitCtx(ConfNode *conf) } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) + if (unlikely(output_ctx == NULL)) return NULL; output_ctx->data = NULL; diff --git a/src/log-httplog.c b/src/log-httplog.c index 098473fac0..15ff9e2caf 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -571,7 +571,7 @@ TmEcode LogHttpLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pack TmEcode LogHttpLogThreadInit(ThreadVars *t, void *initdata, void **data) { LogHttpLogThread *aft = SCMalloc(sizeof(LogHttpLogThread)); - if (aft == NULL) + if (unlikely(aft == NULL)) return TM_ECODE_FAILED; memset(aft, 0, sizeof(LogHttpLogThread)); @@ -639,7 +639,7 @@ OutputCtx *LogHttpLogInitCtx(ConfNode *conf) } LogHttpFileCtx *httplog_ctx = SCMalloc(sizeof(LogHttpFileCtx)); - if (httplog_ctx == NULL) { + if (unlikely(httplog_ctx == NULL)) { LogFileFreeCtx(file_ctx); return NULL; } @@ -713,8 +713,8 @@ OutputCtx *LogHttpLogInitCtx(ConfNode *conf) } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) { - for (n = 0; n < httplog_ctx->cf_n; n++) { + if (unlikely(output_ctx == NULL)) { + for (n = 0;n < httplog_ctx->cf_n;n++) { SCFree(httplog_ctx->cf_nodes[n]); } LogFileFreeCtx(file_ctx); diff --git a/src/log-pcap.c b/src/log-pcap.c index d1a6cba935..f40fe2b0e0 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -378,9 +378,8 @@ TmEcode PcapLogDataDeinit(ThreadVars *t, void *data) OutputCtx *PcapLogInitCtx(ConfNode *conf) { PcapLogData *pl = SCMalloc(sizeof(PcapLogData)); - if (pl == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate Memory for PcapLogData"); + if (unlikely(pl == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate Memory for PcapLogData"); exit(EXIT_FAILURE); } memset(pl, 0, sizeof(PcapLogData)); @@ -561,7 +560,7 @@ OutputCtx *PcapLogInitCtx(ConfNode *conf) /* create the output ctx and send it back */ OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) { + if (unlikely(output_ctx == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for OutputCtx."); exit(EXIT_FAILURE); } @@ -614,7 +613,7 @@ int PcapLogOpenFileCtx(PcapLogData *pl) /* Place to store the name of our PCAP file */ PcapFileName *pf = SCMalloc(sizeof(PcapFileName)); - if (pf == NULL) { + if (unlikely(pf == NULL)) { return -1; } memset(pf, 0, sizeof(PcapFileName)); diff --git a/src/log-tlslog.c b/src/log-tlslog.c index 365c56a5c5..a5c4602a1d 100644 --- a/src/log-tlslog.c +++ b/src/log-tlslog.c @@ -472,7 +472,7 @@ TmEcode LogTlsLog(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packet TmEcode LogTlsLogThreadInit(ThreadVars *t, void *initdata, void **data) { LogTlsLogThread *aft = SCMalloc(sizeof(LogTlsLogThread)); - if (aft == NULL) + if (unlikely(aft == NULL)) return TM_ECODE_FAILED; memset(aft, 0, sizeof(LogTlsLogThread)); @@ -566,7 +566,7 @@ OutputCtx *LogTlsLogInitCtx(ConfNode *conf) } LogTlsFileCtx *tlslog_ctx = SCCalloc(1, sizeof(LogTlsFileCtx)); - if (tlslog_ctx == NULL) + if (unlikely(tlslog_ctx == NULL)) goto filectx_error; tlslog_ctx->file_ctx = file_ctx; @@ -580,7 +580,7 @@ OutputCtx *LogTlsLogInitCtx(ConfNode *conf) } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); - if (output_ctx == NULL) + if (unlikely(output_ctx == NULL)) goto tlslog_error; output_ctx->data = tlslog_ctx; output_ctx->DeInit = LogTlsLogDeInitCtx; diff --git a/src/output.c b/src/output.c index 5400ecbedd..33547c3000 100644 --- a/src/output.c +++ b/src/output.c @@ -47,7 +47,7 @@ OutputRegisterModule(char *name, char *conf_name, OutputCtx *(*InitFunc)(ConfNode *)) { OutputModule *module = SCCalloc(1, sizeof(*module)); - if (module == NULL) { + if (unlikely(module == NULL)) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in OutputRegisterModule. Exiting..."); exit(EXIT_FAILURE); } diff --git a/src/pkt-var.c b/src/pkt-var.c index b15cb0ad75..d4e48526c4 100644 --- a/src/pkt-var.c +++ b/src/pkt-var.c @@ -62,7 +62,7 @@ void PktVarAdd(Packet *p, char *name, uint8_t *value, uint16_t size) { PktVar *pv = PktVarGet(p, name); if (pv == NULL) { pv = SCMalloc(sizeof(PktVar)); - if (pv == NULL) + if (unlikely(pv == NULL)) return; pv->name = name; diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index aaceb55ee8..8d61c01a5c 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -121,7 +121,7 @@ void *ParseAFPConfig(const char *iface) char *bpf_filter = NULL; char *out_iface = NULL; - if (aconf == NULL) { + if (unlikely(aconf == NULL)) { return NULL; } diff --git a/src/runmode-erf-file.c b/src/runmode-erf-file.c index b514944757..4e70e07135 100644 --- a/src/runmode-erf-file.c +++ b/src/runmode-erf-file.c @@ -210,7 +210,7 @@ int RunModeErfFileAutoFp(DetectEngineCtx *de_ctx) SCLogDebug("tname %s, qname %s", tname, qname); char *thread_name = SCStrdup(tname); - if (thread_name == NULL) { + if (unlikely(thread_name == NULL)) { printf("ERROR: Can't allocate thread name\n"); exit(EXIT_FAILURE); } @@ -253,7 +253,7 @@ int RunModeErfFileAutoFp(DetectEngineCtx *de_ctx) } char *thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { + if (unlikely(thread_group_name == NULL)) { printf("Error allocating memory\n"); exit(EXIT_FAILURE); } diff --git a/src/runmode-napatech.c b/src/runmode-napatech.c index cbc11221ad..5bf4451c13 100644 --- a/src/runmode-napatech.c +++ b/src/runmode-napatech.c @@ -95,24 +95,24 @@ int RunModeNapatechAuto(DetectEngineCtx *de_ctx) { for (feed=0; feed < feed_count; feed++) { snprintf(tname, sizeof(tname),"%"PRIu16":%"PRIu16, adapter, feed); feedName = SCStrdup(tname); - if (feedName == NULL) { - fprintf(stderr, "ERROR: Alloc feed name\n"); - exit(EXIT_FAILURE); + if (unlikely(feedName == NULL)) { + fprintf(stderr, "ERROR: Alloc feed name\n"); + exit(EXIT_FAILURE); } snprintf(tname, sizeof(tname),"Feed%"PRIu16,feed); threadName = SCStrdup(tname); - if (threadName == NULL) { - fprintf(stderr, "ERROR: Alloc thread name\n"); - exit(EXIT_FAILURE); + if (unlikely(threadName == NULL)) { + fprintf(stderr, "ERROR: Alloc thread name\n"); + exit(EXIT_FAILURE); } snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed); outQueueName = SCStrdup(tname); - if (outQueueName == NULL) { - fprintf(stderr, "ERROR: Alloc output queue name\n"); - exit(EXIT_FAILURE); + if (unlikely(outQueueName == NULL)) { + fprintf(stderr, "ERROR: Alloc output queue name\n"); + exit(EXIT_FAILURE); } /* create the threads */ @@ -162,15 +162,15 @@ int RunModeNapatechAuto(DetectEngineCtx *de_ctx) { { snprintf(tname, sizeof(tname),"Detect%"PRIu16"/%"PRIu16,feed,detect++); threadName = SCStrdup(tname); - if (threadName == NULL) { - fprintf(stderr, "ERROR: can not strdup thread name\n"); - exit(EXIT_FAILURE); + if (unlikely(threadName == NULL)) { + fprintf(stderr, "ERROR: can not strdup thread name\n"); + exit(EXIT_FAILURE); } snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed); inQueueName = SCStrdup(tname); - if (inQueueName == NULL) { - fprintf(stderr, "ERROR: can not strdup in queue name\n"); - exit(EXIT_FAILURE); + if (unlikely(inQueueName == NULL)) { + fprintf(stderr, "ERROR: can not strdup in queue name\n"); + exit(EXIT_FAILURE); } ThreadVars *tv_detect = TmThreadCreatePacketHandler(threadName, @@ -196,17 +196,17 @@ int RunModeNapatechAuto(DetectEngineCtx *de_ctx) { TmSlotSetFuncAppend(tv_detect,tm_module,(void *)de_ctx); thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { - fprintf(stderr, "Error allocating memory\n"); - exit(EXIT_FAILURE); + if (unlikely(thread_group_name == NULL)) { + fprintf(stderr, "Error allocating memory\n"); + exit(EXIT_FAILURE); } tv_detect->thread_group_name = thread_group_name; SetupOutputs(tv_detect); thread_group_name = SCStrdup("Outputs"); - if (thread_group_name == NULL) { - fprintf(stderr, "Error allocating memory\n"); - exit(EXIT_FAILURE); + if (unlikely(thread_group_name == NULL)) { + fprintf(stderr, "Error allocating memory\n"); + exit(EXIT_FAILURE); } tv_detect->thread_group_name = thread_group_name; @@ -262,23 +262,23 @@ int RunModeNapatechAuto2(DetectEngineCtx *de_ctx) { for (feed=0; feed < feed_count; feed++) { snprintf(tname, sizeof(tname),"%"PRIu16":%"PRIu16, adapter, feed); feedName = SCStrdup(tname); - if (feedName == NULL) { - fprintf(stderr, "ERROR: can not strdup feed name\n"); - exit(EXIT_FAILURE); + if (unlikely(feedName == NULL)) { + fprintf(stderr, "ERROR: can not strdup feed name\n"); + exit(EXIT_FAILURE); } snprintf(tname, sizeof(tname),"Feed%"PRIu16,feed); threadName = SCStrdup(tname); - if (threadName == NULL) { - fprintf(stderr, "ERROR: can not strdup in thread name\n"); - exit(EXIT_FAILURE); + if (unlikely(threadName == NULL)) { + fprintf(stderr, "ERROR: can not strdup in thread name\n"); + exit(EXIT_FAILURE); } snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed); outQueueName = SCStrdup(tname); - if (outQueueName == NULL) { - fprintf(stderr, "ERROR: can not strdup out queue name\n"); - exit(EXIT_FAILURE); + if (unlikely(outQueueName == NULL)) { + fprintf(stderr, "ERROR: can not strdup out queue name\n"); + exit(EXIT_FAILURE); } /* create the threads */ @@ -322,17 +322,17 @@ int RunModeNapatechAuto2(DetectEngineCtx *de_ctx) { TmSlotSetFuncAppend(tv_napatechFeed,tm_module,(void *)de_ctx); thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { - fprintf(stderr, "Error allocating memory\n"); - exit(EXIT_FAILURE); + if (unlikely(thread_group_name == NULL)) { + fprintf(stderr, "Error allocating memory\n"); + exit(EXIT_FAILURE); } tv_napatechFeed->thread_group_name = thread_group_name; SetupOutputs(tv_napatechFeed); thread_group_name = SCStrdup("Outputs"); - if (thread_group_name == NULL) { - fprintf(stderr, "Error allocating memory\n"); - exit(EXIT_FAILURE); + if (unlikely(thread_group_name == NULL)) { + fprintf(stderr, "Error allocating memory\n"); + exit(EXIT_FAILURE); } tv_napatechFeed->thread_group_name = thread_group_name; diff --git a/src/runmode-pcap-file.c b/src/runmode-pcap-file.c index 9829b8eee0..e1ab4b09cb 100644 --- a/src/runmode-pcap-file.c +++ b/src/runmode-pcap-file.c @@ -293,7 +293,7 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx) snprintf(tname, sizeof(tname), "Detect%"PRIu16, thread+1); char *thread_name = SCStrdup(tname); - if (thread_name == NULL) { + if (unlikely(thread_name == NULL)) { printf("ERROR: Can not strdup thread name\n"); exit(EXIT_FAILURE); } @@ -318,7 +318,7 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx) TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET); char *thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { + if (unlikely(thread_group_name == NULL)) { printf("Error allocating memory\n"); exit(EXIT_FAILURE); } @@ -460,7 +460,7 @@ int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx) SCLogDebug("tname %s, qname %s", tname, qname); char *thread_name = SCStrdup(tname); - if (thread_name == NULL) { + if (unlikely(thread_name == NULL)) { printf("ERROR: Can not strdup thread name\n"); exit(EXIT_FAILURE); } @@ -503,7 +503,7 @@ int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx) } char *thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { + if (unlikely(thread_group_name == NULL)) { printf("Error allocating memory\n"); exit(EXIT_FAILURE); } diff --git a/src/runmode-pcap.c b/src/runmode-pcap.c index 3281fdeee1..afd20ef4b4 100644 --- a/src/runmode-pcap.c +++ b/src/runmode-pcap.c @@ -93,7 +93,7 @@ void *ParsePcapConfig(const char *iface) char *tmpctype; intmax_t value; - if (aconf == NULL) { + if (unlikely(aconf == NULL)) { return NULL; } diff --git a/src/runmode-pfring.c b/src/runmode-pfring.c index 2aec1459c7..d932864a8c 100644 --- a/src/runmode-pfring.c +++ b/src/runmode-pfring.c @@ -114,7 +114,7 @@ void *OldParsePfringConfig(const char *iface) cluster_type default_ctype = CLUSTER_ROUND_ROBIN; #endif - if (pfconf == NULL) { + if (unlikely(pfconf == NULL)) { return NULL; } @@ -206,7 +206,7 @@ void *ParsePfringConfig(const char *iface) char *bpf_filter = NULL; #endif /* HAVE_PFRING_SET_BPF_FILTER */ - if (pfconf == NULL) { + if (unlikely(pfconf == NULL)) { return NULL; } diff --git a/src/runmodes.c b/src/runmodes.c index 4802eb8eba..f766ccac1c 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -433,7 +433,7 @@ void RunModeInitializeOutputs(void) debuglog_enabled = 1; RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput)); - if (runmode_output == NULL) + if (unlikely(runmode_output == NULL)) return; runmode_output->tm_module = tm_module; runmode_output->output_ctx = output_ctx; diff --git a/src/source-af-packet.c b/src/source-af-packet.c index f91a39ce7f..ccff2cd468 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -339,7 +339,7 @@ TmEcode AFPPeersListAdd(AFPThreadVars *ptv) AFPPeer *pitem; int mtu, out_mtu; - if (peer == NULL) { + if (unlikely(peer == NULL)) { SCReturnInt(TM_ECODE_FAILED); } memset(peer, 0, sizeof(AFPPeer)); @@ -1434,7 +1434,7 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, void *initdata, void **data) { } AFPThreadVars *ptv = SCMalloc(sizeof(AFPThreadVars)); - if (ptv == NULL) { + if (unlikely(ptv == NULL)) { afpconfig->DerefFunc(afpconfig); SCReturnInt(TM_ECODE_FAILED); } diff --git a/src/source-erf-dag.c b/src/source-erf-dag.c index bc9b992e36..150d21723b 100644 --- a/src/source-erf-dag.c +++ b/src/source-erf-dag.c @@ -169,9 +169,8 @@ ReceiveErfDagThreadInit(ThreadVars *tv, void *initdata, void **data) } ErfDagThreadVars *ewtn = SCMalloc(sizeof(ErfDagThreadVars)); - if (ewtn == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate memory for ERF DAG thread vars."); + if (unlikely(ewtn == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for ERF DAG thread vars."); exit(EXIT_FAILURE); } diff --git a/src/source-erf-file.c b/src/source-erf-file.c index 8e8b23aa05..44c3642fef 100644 --- a/src/source-erf-file.c +++ b/src/source-erf-file.c @@ -227,9 +227,8 @@ ReceiveErfFileThreadInit(ThreadVars *tv, void *initdata, void **data) } ErfFileThreadVars *etv = SCMalloc(sizeof(ErfFileThreadVars)); - if (etv == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate memory for ERF file thread vars."); + if (unlikely(etv == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for ERF file thread vars."); fclose(erf); SCReturnInt(TM_ECODE_FAILED); } diff --git a/src/source-napatech.c b/src/source-napatech.c index f74d4ab16e..56c37e84b6 100644 --- a/src/source-napatech.c +++ b/src/source-napatech.c @@ -159,9 +159,8 @@ TmEcode NapatechFeedThreadInit(ThreadVars *tv, void *initdata, void **data) } NapatechThreadVars *ntv = SCMalloc(sizeof(NapatechThreadVars)); - if (ntv == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate memory for NAPATECH thread vars."); + if (unlikely(ntv == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for NAPATECH thread vars."); exit(EXIT_FAILURE); } diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index 5174ea9291..e23e620b02 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -217,7 +217,7 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, void *initdata, void **data) { SCLogInfo("reading pcap file %s", (char *)initdata); PcapFileThreadVars *ptv = SCMalloc(sizeof(PcapFileThreadVars)); - if (ptv == NULL) + if (unlikely(ptv == NULL)) SCReturnInt(TM_ECODE_FAILED); memset(ptv, 0, sizeof(PcapFileThreadVars)); diff --git a/src/source-pcap.c b/src/source-pcap.c index 657e1229db..bb7cda1593 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -340,7 +340,7 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { } PcapThreadVars *ptv = SCMalloc(sizeof(PcapThreadVars)); - if (ptv == NULL) { + if (unlikely(ptv == NULL)) { pcapconfig->DerefFunc(pcapconfig); SCReturnInt(TM_ECODE_FAILED); } @@ -480,8 +480,7 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { } PcapThreadVars *ptv = SCMalloc(sizeof(PcapThreadVars)); - if (ptv == NULL) { - /* Dereference config */ + if (unlikely(ptv == NULL)) { pcapconfig->DerefFunc(pcapconfig); SCReturnInt(TM_ECODE_FAILED); } diff --git a/src/source-pfring.c b/src/source-pfring.c index e433fc40d5..c169b36b6f 100644 --- a/src/source-pfring.c +++ b/src/source-pfring.c @@ -332,7 +332,7 @@ TmEcode ReceivePfringThreadInit(ThreadVars *tv, void *initdata, void **data) { return TM_ECODE_FAILED; PfringThreadVars *ptv = SCMalloc(sizeof(PfringThreadVars)); - if (ptv == NULL) { + if (unlikely(ptv == NULL)) { pfconf->DerefFunc(pfconf); return TM_ECODE_FAILED; } diff --git a/src/stream-tcp-inline.c b/src/stream-tcp-inline.c index 60f6d38b2d..dbc2685a8d 100644 --- a/src/stream-tcp-inline.c +++ b/src/stream-tcp-inline.c @@ -199,7 +199,7 @@ static int StreamTcpInlineTest01(void) { p->tcph->th_seq = htonl(10000000UL); t = SCMalloc(sizeof(TcpSegment)); - if (t == NULL) { + if (unlikely(t == NULL)) { printf("alloc TcpSegment failed: "); goto end; } @@ -259,7 +259,7 @@ static int StreamTcpInlineTest02(void) { p->tcph->th_seq = htonl(10000001UL); t = SCMalloc(sizeof(TcpSegment)); - if (t == NULL) { + if (unlikely(t == NULL)) { printf("alloc TcpSegment failed: "); goto end; } @@ -324,7 +324,7 @@ static int StreamTcpInlineTest03(void) { p->tcph->th_seq = htonl(10000000UL); t = SCMalloc(sizeof(TcpSegment)); - if (t == NULL) { + if (unlikely(t == NULL)) { printf("alloc TcpSegment failed: "); goto end; } @@ -389,7 +389,7 @@ static int StreamTcpInlineTest04(void) { p->tcph->th_seq = htonl(10000003UL); t = SCMalloc(sizeof(TcpSegment)); - if (t == NULL) { + if (unlikely(t == NULL)) { printf("alloc TcpSegment failed: "); goto end; } @@ -453,7 +453,7 @@ static int StreamTcpInlineTest05(void) { p->tcph->th_seq = htonl(10000000UL); t = SCMalloc(sizeof(TcpSegment)); - if (t == NULL) { + if (unlikely(t == NULL)) { printf("alloc TcpSegment failed: "); goto end; } @@ -518,7 +518,7 @@ static int StreamTcpInlineTest06(void) { p->tcph->th_seq = htonl(10000020UL); t = SCMalloc(sizeof(TcpSegment)); - if (t == NULL) { + if (unlikely(t == NULL)) { printf("alloc TcpSegment failed: "); goto end; } @@ -583,7 +583,7 @@ static int StreamTcpInlineTest07(void) { p->tcph->th_seq = htonl(10000000UL); t = SCMalloc(sizeof(TcpSegment)); - if (t == NULL) { + if (unlikely(t == NULL)) { printf("alloc TcpSegment failed: "); goto end; } diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index cc4df3afe8..9347c14509 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -163,7 +163,7 @@ void *TcpSegmentPoolAlloc() TcpSegment *seg = NULL; seg = SCMalloc(sizeof (TcpSegment)); - if (seg == NULL) + if (unlikely(seg == NULL)) return NULL; return seg; } @@ -357,7 +357,7 @@ TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(void) { SCEnter(); TcpReassemblyThreadCtx *ra_ctx = SCMalloc(sizeof(TcpReassemblyThreadCtx)); - if (ra_ctx == NULL) + if (unlikely(ra_ctx == NULL)) return NULL; memset(ra_ctx, 0x00, sizeof(TcpReassemblyThreadCtx)); @@ -3607,7 +3607,7 @@ static int StreamTcpReassembleStreamTest(TcpStream *stream) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; uint8_t payload[4]; @@ -3967,7 +3967,7 @@ static int StreamTcpCheckQueue (uint8_t *stream_contents, StreamMsgQueue *q, uin static int StreamTcpTestStartsBeforeListSegment(TcpStream *stream) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; uint8_t payload[4]; @@ -4084,7 +4084,7 @@ static int StreamTcpTestStartsBeforeListSegment(TcpStream *stream) { static int StreamTcpTestStartsAtSameListSegment(TcpStream *stream) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; uint8_t payload[4]; @@ -4200,7 +4200,7 @@ static int StreamTcpTestStartsAtSameListSegment(TcpStream *stream) { static int StreamTcpTestStartsAfterListSegment(TcpStream *stream) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; uint8_t payload[4]; @@ -4919,7 +4919,7 @@ static int StreamTcpTestMissedPacket (TcpReassemblyThreadCtx *ra_ctx, uint16_t len, uint8_t th_flags, uint8_t flowflags, uint8_t state) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return -1; Flow f; TCPHdr tcph; @@ -5517,7 +5517,7 @@ end: static int StreamTcpReassembleTest32(void) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; TCPHdr tcph; @@ -5607,7 +5607,7 @@ end: static int StreamTcpReassembleTest33(void) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; TCPHdr tcph; @@ -5688,7 +5688,7 @@ static int StreamTcpReassembleTest33(void) { static int StreamTcpReassembleTest34(void) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; TCPHdr tcph; @@ -5770,7 +5770,7 @@ static int StreamTcpReassembleTest34(void) { static int StreamTcpReassembleTest35(void) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; TCPHdr tcph; @@ -5839,7 +5839,7 @@ static int StreamTcpReassembleTest35(void) { static int StreamTcpReassembleTest36(void) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; TCPHdr tcph; @@ -5915,7 +5915,7 @@ static int StreamTcpReassembleTest37(void) { ThreadVars tv; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; StreamTcpInitConfig(TRUE); @@ -6000,7 +6000,7 @@ static int StreamTcpReassembleTest37(void) { static int StreamTcpReassembleTest38 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; TCPHdr tcph; @@ -6158,7 +6158,7 @@ static int StreamTcpReassembleTest39 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow *f = NULL; TCPHdr tcph; @@ -6367,7 +6367,7 @@ end: static int StreamTcpReassembleTest40 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow *f = NULL; TCPHdr tcph; @@ -6609,7 +6609,7 @@ end: static int StreamTcpReassembleTest41 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow *f = NULL; TCPHdr tcph; @@ -6798,7 +6798,7 @@ end: static int StreamTcpReassembleTest42 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow *f = NULL; TCPHdr tcph; @@ -6952,7 +6952,7 @@ end: static int StreamTcpReassembleTest43 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow *f = NULL; TCPHdr tcph; @@ -7190,7 +7190,7 @@ end: static int StreamTcpReassembleTest45 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow *f = NULL; TCPHdr tcph; @@ -7308,7 +7308,7 @@ end: static int StreamTcpReassembleTest46 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow *f = NULL; TCPHdr tcph; @@ -7430,7 +7430,7 @@ end: static int StreamTcpReassembleTest47 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow *f = NULL; TCPHdr tcph; diff --git a/src/stream-tcp-sack.c b/src/stream-tcp-sack.c index 2ec593af0c..aae8d381b1 100644 --- a/src/stream-tcp-sack.c +++ b/src/stream-tcp-sack.c @@ -63,7 +63,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re) SCLogDebug("SEQ_LT(re, rec->le)"); // entirely before, prepend StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); - if (stsr == NULL) { + if (unlikely(stsr == NULL)) { SCReturnInt(-1); } stsr->le = le; @@ -149,7 +149,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re) if (rec->next == NULL) { SCLogDebug("rec->next == NULL"); StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); - if (stsr == NULL) { + if (unlikely(stsr == NULL)) { SCReturnInt(-1); } stsr->le = le; @@ -164,7 +164,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re) if (SEQ_LT(le, rec->next->le) && SEQ_LT(re, rec->next->le)) { SCLogDebug("SEQ_LT(le, rec->next->le) && SEQ_LT(re, rec->next->le)"); StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); - if (stsr == NULL) { + if (unlikely(stsr == NULL)) { SCReturnInt(-1); } stsr->le = le; @@ -175,7 +175,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re) } else if (SEQ_LT(le, rec->next->le) && SEQ_GEQ(re, rec->next->le)) { SCLogDebug("SEQ_LT(le, rec->next->le) && SEQ_GEQ(re, rec->next->le)"); StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); - if (stsr == NULL) { + if (unlikely(stsr == NULL)) { SCReturnInt(-1); } stsr->le = le; @@ -192,7 +192,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re) } else { SCLogDebug("implied empty list"); StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); - if (stsr == NULL) { + if (unlikely(stsr == NULL)) { SCReturnInt(-1); } stsr->le = le; diff --git a/src/stream-tcp.c b/src/stream-tcp.c index e1c97498bf..596928f013 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -254,7 +254,7 @@ void *StreamTcpSessionPoolAlloc() return NULL; ptr = SCMalloc(sizeof(TcpSession)); - if (ptr == NULL) + if (unlikely(ptr == NULL)) return NULL; return ptr; @@ -3767,7 +3767,7 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data) { SCEnter(); StreamTcpThread *stt = SCMalloc(sizeof(StreamTcpThread)); - if (stt == NULL) + if (unlikely(stt == NULL)) SCReturnInt(TM_ECODE_FAILED); memset(stt, 0, sizeof(StreamTcpThread)); @@ -4671,7 +4671,7 @@ int StreamTcpSegmentForEach(Packet *p, uint8_t flag, StreamSegmentCallback Callb static int StreamTcpTest01 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; memset(p, 0, SIZE_OF_PACKET); @@ -4717,7 +4717,7 @@ end: static int StreamTcpTest02 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -4816,7 +4816,7 @@ end: static int StreamTcpTest03 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -4890,7 +4890,7 @@ end: static int StreamTcpTest04 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -4957,7 +4957,7 @@ end: static int StreamTcpTest05 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -5060,7 +5060,7 @@ end: static int StreamTcpTest06 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; TcpSession ssn; @@ -5123,7 +5123,7 @@ end: static int StreamTcpTest07 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -5211,7 +5211,7 @@ end: static int StreamTcpTest08 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -5301,7 +5301,7 @@ end: static int StreamTcpTest09 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -5377,7 +5377,7 @@ end: static int StreamTcpTest10 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -5477,7 +5477,7 @@ end: static int StreamTcpTest11 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -5578,7 +5578,7 @@ end: static int StreamTcpTest12 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -5672,7 +5672,7 @@ end: static int StreamTcpTest13 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -5870,7 +5870,7 @@ char *StreamTcpParseOSPolicy (char *conf_var_name) static int StreamTcpTest14 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -6041,7 +6041,7 @@ end: static int StreamTcp4WHSTest01 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -6121,7 +6121,7 @@ end: static int StreamTcp4WHSTest02 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -6190,7 +6190,7 @@ end: static int StreamTcp4WHSTest03 (void) { int ret = 0; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -6268,7 +6268,7 @@ end: static int StreamTcpTest15 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -6438,7 +6438,7 @@ end: static int StreamTcpTest16 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -6609,7 +6609,7 @@ end: static int StreamTcpTest17 (void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -6779,7 +6779,7 @@ static int StreamTcpTest18 (void) { char *ip_addr; TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ipv4h; int ret = 0; @@ -6828,7 +6828,7 @@ static int StreamTcpTest19 (void) { char *ip_addr; TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ipv4h; int ret = 0; @@ -6880,7 +6880,7 @@ static int StreamTcpTest20 (void) { char *ip_addr; TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ipv4h; int ret = 0; @@ -6932,7 +6932,7 @@ static int StreamTcpTest21 (void) { char *ip_addr; TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ipv4h; int ret = 0; @@ -6984,7 +6984,7 @@ static int StreamTcpTest22 (void) { char *ip_addr; TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; IPV4Hdr ipv4h; int ret = 0; @@ -7041,7 +7041,7 @@ static int StreamTcpTest23(void) PacketQueue pq; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; memset(&pq,0,sizeof(PacketQueue)); @@ -7123,7 +7123,7 @@ static int StreamTcpTest24(void) { TcpSession ssn; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; TCPHdr tcph; @@ -7213,7 +7213,7 @@ end: */ static int StreamTcpTest25(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -7311,7 +7311,7 @@ end: */ static int StreamTcpTest26(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -7405,7 +7405,7 @@ end: */ static int StreamTcpTest27(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -8393,7 +8393,7 @@ end: */ static int StreamTcpTest37(void) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; Flow f; ThreadVars tv; @@ -8534,7 +8534,7 @@ static int StreamTcpTest38 (void) { memset(&pq,0,sizeof(PacketQueue)); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); @@ -8650,7 +8650,7 @@ static int StreamTcpTest39 (void) { memset(&pq,0,sizeof(PacketQueue)); Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); @@ -8753,7 +8753,7 @@ static int StreamTcpTest40(void) { 0x00, 0x04, 0xf0, 0xc8, 0x01, 0x99, 0xa3, 0xf3 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; @@ -8811,7 +8811,7 @@ static int StreamTcpTest41(void) { 0x04, 0x02, 0x08, 0x0a, 0x00, 0xdd, 0x1a, 0x39, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x02 }; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return 0; ThreadVars tv; DecodeThreadVars dtv; diff --git a/src/stream.c b/src/stream.c index 96e896ba03..d6f8a9a79c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -170,7 +170,7 @@ void StreamMsgQueuesDeinit(char quiet) { * \retval smq ptr to the queue or NULL */ StreamMsgQueue *StreamMsgQueueGetNew(void) { StreamMsgQueue *smq = SCMalloc(sizeof(StreamMsgQueue)); - if (smq == NULL) + if (unlikely(smq == NULL)) return NULL; memset(smq, 0x00, sizeof(StreamMsgQueue)); diff --git a/src/suricata.c b/src/suricata.c index 1a1c6b3eaf..aeb2c2d2e5 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -360,7 +360,7 @@ static void SetBpfString(int optind, char *argv[]) { return; bpf_filter = SCMalloc(bpf_len); - if (bpf_filter == NULL) + if (unlikely(bpf_filter == NULL)) return; memset(bpf_filter, 0x00, bpf_len); @@ -411,9 +411,8 @@ static void SetBpfStringFromFile(char *filename) { } bpf_filter = SCMalloc(bpf_len * sizeof(char)); - if (bpf_filter == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate buffer for bpf filter in file %s", filename); + if (unlikely(bpf_filter == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate buffer for bpf filter in file %s", filename); exit(EXIT_FAILURE); } memset(bpf_filter, 0x00, bpf_len); diff --git a/src/tm-queues.c b/src/tm-queues.c index 80c392447c..e7afcb53c5 100644 --- a/src/tm-queues.c +++ b/src/tm-queues.c @@ -35,7 +35,7 @@ static Tmq tmqs[TMQ_MAX_QUEUES]; Tmq* TmqAlloc(void) { Tmq *q = SCMalloc(sizeof(Tmq)); - if (q == NULL) + if (unlikely(q == NULL)) goto error; memset(q, 0, sizeof(Tmq)); diff --git a/src/tm-threads.c b/src/tm-threads.c index b14db4d8b5..3286da52d9 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -907,7 +907,7 @@ ThreadVars *TmThreadsGetTVContainingSlot(TmSlot *tm_slot) static inline TmSlot * _TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, void *data) { TmSlot *slot = SCMalloc(sizeof(TmSlot)); - if (slot == NULL) + if (unlikely(slot == NULL)) return NULL; memset(slot, 0, sizeof(TmSlot)); SC_ATOMIC_INIT(slot->slot_data); @@ -987,7 +987,7 @@ void TmSlotSetFuncAppendDelayed(ThreadVars *tv, TmModule *tm, void *data, } dslot = SCMalloc(sizeof(TmDummySlot)); - if (dslot == NULL) { + if (unlikely(dslot == NULL)) { return; } @@ -1309,7 +1309,7 @@ ThreadVars *TmThreadCreate(char *name, char *inq_name, char *inqh_name, /* XXX create separate function for this: allocate a thread container */ tv = SCMalloc(sizeof(ThreadVars)); - if (tv == NULL) + if (unlikely(tv == NULL)) goto error; memset(tv, 0, sizeof(ThreadVars)); diff --git a/src/tmqh-flow.c b/src/tmqh-flow.c index 9ed6b2df06..6382ac238e 100644 --- a/src/tmqh-flow.c +++ b/src/tmqh-flow.c @@ -154,12 +154,12 @@ void *TmqhOutputFlowSetupCtx(char *queue_str) return NULL; TmqhFlowCtx *ctx = SCMalloc(sizeof(TmqhFlowCtx)); - if (ctx == NULL) + if (unlikely(ctx == NULL)) return NULL; memset(ctx,0x00,sizeof(TmqhFlowCtx)); char *str = SCStrdup(queue_str); - if (str == NULL) { + if (unlikely(str == NULL)) { goto error; } char *tstr = str; diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index 1844f7cc12..84a7f6a021 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -116,7 +116,7 @@ void PacketPoolInit(intmax_t max_pending_packets) { for (i = 0; i < max_pending_packets; i++) { /* XXX pkt alloc function */ Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) { + if (unlikely(p == NULL)) { SCLogError(SC_ERR_FATAL, "Fatal error encountered while allocating a packet. Exiting..."); exit(EXIT_FAILURE); } diff --git a/src/util-bloomfilter-counting.c b/src/util-bloomfilter-counting.c index c6d58e055c..4e44e68ef2 100644 --- a/src/util-bloomfilter-counting.c +++ b/src/util-bloomfilter-counting.c @@ -49,7 +49,7 @@ BloomFilterCounting *BloomFilterCountingInit(uint32_t size, uint8_t type, uint8_ /* setup the filter */ bf = SCMalloc(sizeof(BloomFilterCounting)); - if (bf == NULL) + if (unlikely(bf == NULL)) goto error; memset(bf,0,sizeof(BloomFilterCounting)); bf->type = type; /* size of the type: 1, 2, 4 */ diff --git a/src/util-bloomfilter.c b/src/util-bloomfilter.c index 0bc17bbc20..b2c9553dcb 100644 --- a/src/util-bloomfilter.c +++ b/src/util-bloomfilter.c @@ -40,7 +40,7 @@ BloomFilter *BloomFilterInit(uint32_t size, uint8_t iter, uint32_t (*Hash)(void /* setup the filter */ bf = SCMalloc(sizeof(BloomFilter)); - if (bf == NULL) + if (unlikely(bf == NULL)) goto error; memset(bf,0,sizeof(BloomFilter)); bf->bitarray_size = size; diff --git a/src/util-buffer.c b/src/util-buffer.c index 675ba06678..8dd108e8ef 100644 --- a/src/util-buffer.c +++ b/src/util-buffer.c @@ -40,7 +40,7 @@ MemBuffer *MemBufferCreateNew(uint32_t size) uint32_t total_size = size + sizeof(MemBuffer); MemBuffer *buffer = SCMalloc(total_size); - if (buffer == NULL) { + if (unlikely(buffer == NULL)) { return NULL; } memset(buffer, 0, total_size); diff --git a/src/util-cuda-handlers.c b/src/util-cuda-handlers.c index e340357384..f338426c6d 100644 --- a/src/util-cuda-handlers.c +++ b/src/util-cuda-handlers.c @@ -118,7 +118,7 @@ void SCCudaHlGetYamlConf(void) /* "mpm" profile, found under "cuda.mpm" in the conf file */ profile = SCMalloc(sizeof(SCCudaHlCudaProfile)); - if (profile == NULL) { + if (unlikely(profile == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -309,7 +309,7 @@ int SCCudaHlGetCudaModuleFromFile(CUmodule *p_module, const char *filename, int /* Register new CUmodule in the module */ new_module_cumodule = SCMalloc(sizeof(SCCudaHlModuleCUmodule)); - if (new_module_cumodule == NULL) { + if (unlikely(new_module_cumodule == NULL)) { exit(EXIT_FAILURE); } memset(new_module_cumodule, 0, sizeof(SCCudaHlModuleCUmodule)); @@ -462,7 +462,7 @@ int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle) /* Register new CUmodule in the module */ new_module_cumodule = SCMalloc(sizeof(SCCudaHlModuleCUmodule)); - if (new_module_cumodule == NULL) { + if (unlikely(new_module_cumodule == NULL)) { exit(EXIT_FAILURE); } memset(new_module_cumodule, 0, sizeof(SCCudaHlModuleCUmodule)); @@ -470,7 +470,7 @@ int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle) /* select the ptx image based on the compute capability supported by all * devices (i.e. the lowest) */ char* image = SCMalloc(strlen(ptx_image)+15); - if (image == NULL) { + if (unlikely(image == NULL)) { exit(EXIT_FAILURE); } memset(image, 0x0, sizeof(image)); @@ -623,7 +623,7 @@ int SCCudaHlGetCudaDevicePtr(CUdeviceptr *device_ptr, const char *name, } new_module_device_ptr = SCMalloc(sizeof(SCCudaHlModuleDevicePointer)); - if (new_module_device_ptr == NULL) + if (unlikely(new_module_device_ptr == NULL)) goto error; memset(new_module_device_ptr, 0, sizeof(SCCudaHlModuleDevicePointer)); @@ -857,7 +857,7 @@ int SCCudaHlRegisterModule(const char *name) /* the module is not already registered. Register the module */ new_data = SCMalloc(sizeof(SCCudaHlModuleData)); - if (new_data == NULL) { + if (unlikely(new_data == NULL)) { exit(EXIT_FAILURE); } memset(new_data, 0, sizeof(SCCudaHlModuleData)); diff --git a/src/util-cuda.c b/src/util-cuda.c index a494e2d64d..d224f1316f 100644 --- a/src/util-cuda.c +++ b/src/util-cuda.c @@ -4130,7 +4130,7 @@ static int SCCudaDeviceGetAttribute(int *pi, CUdevice_attribute attrib, static SCCudaDevice *SCCudaAllocSCCudaDevice(void) { SCCudaDevice *device = SCMalloc(sizeof(SCCudaDevice)); - if (device == NULL) + if (unlikely(device == NULL)) return NULL; memset(device, 0 , sizeof(SCCudaDevice)); @@ -4159,7 +4159,7 @@ static void SCCudaDeAllocSCCudaDevice(SCCudaDevice *device) static SCCudaDevices *SCCudaAllocSCCudaDevices(void) { SCCudaDevices *devices = SCMalloc(sizeof(SCCudaDevices)); - if (devices == NULL) + if (unlikely(devices == NULL)) return NULL; memset(devices, 0 , sizeof(SCCudaDevices)); diff --git a/src/util-debug.c b/src/util-debug.c index 4297bf9d04..a0f6031739 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -299,7 +299,7 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file, } char *temp_fmt = SCStrdup(sc_log_config->log_format); - if (temp_fmt == NULL) { + if (unlikely(temp_fmt == NULL)) { return SC_ERR_MEM_ALLOC; } char *temp_fmt_h = temp_fmt; @@ -1362,7 +1362,7 @@ static char *SCLogGetLogFilename(char *filearg) log_dir = DEFAULT_LOG_DIR; log_filename = SCMalloc(PATH_MAX); - if (log_filename == NULL) + if (unlikely(log_filename == NULL)) return NULL; snprintf(log_filename, PATH_MAX, "%s/%s", log_dir, filearg); diff --git a/src/util-decode-asn1.c b/src/util-decode-asn1.c index 793b9aa37a..71e974d1d3 100644 --- a/src/util-decode-asn1.c +++ b/src/util-decode-asn1.c @@ -338,7 +338,7 @@ uint8_t SCAsn1CheckBounds(Asn1Ctx *ac) { Asn1Ctx *SCAsn1CtxNew(void) { Asn1Ctx *ac = SCMalloc(sizeof(Asn1Ctx)); - if (ac == NULL) { + if (unlikely(ac == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); return NULL; } diff --git a/src/util-device.c b/src/util-device.c index 6d880edbfe..1a4f402ec0 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -43,7 +43,7 @@ static TAILQ_HEAD(, LiveDevice_) live_devices = int LiveRegisterDevice(char *dev) { LiveDevice *pd = SCMalloc(sizeof(LiveDevice)); - if (pd == NULL) { + if (unlikely(pd == NULL)) { return -1; } diff --git a/src/util-file.c b/src/util-file.c index 5486d8aa15..690e489be5 100644 --- a/src/util-file.c +++ b/src/util-file.c @@ -182,7 +182,7 @@ void FilePrune(FileContainer *ffc) { */ FileContainer *FileContainerAlloc(void) { FileContainer *new = SCMalloc(sizeof(FileContainer)); - if (new == NULL) { + if (unlikely(new == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating mem"); return NULL; } @@ -240,7 +240,7 @@ void FileContainerFree(FileContainer *ffc) { */ static FileData *FileDataAlloc(uint8_t *data, uint32_t data_len) { FileData *new = SCMalloc(sizeof(FileData)); - if (new == NULL) { + if (unlikely(new == NULL)) { return NULL; } memset(new, 0, sizeof(FileData)); @@ -286,7 +286,7 @@ static void FileDataFree(FileData *ffd) { */ static File *FileAlloc(uint8_t *name, uint16_t name_len) { File *new = SCMalloc(sizeof(File)); - if (new == NULL) { + if (unlikely(new == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating mem"); return NULL; } diff --git a/src/util-hash.c b/src/util-hash.c index b74415fa61..125165f266 100644 --- a/src/util-hash.c +++ b/src/util-hash.c @@ -46,8 +46,8 @@ HashTable* HashTableInit(uint32_t size, uint32_t (*Hash)(struct HashTable_ *, vo /* setup the filter */ ht = SCMalloc(sizeof(HashTable)); - if (ht == NULL) - goto error; + if (unlikely(ht == NULL)) + goto error; memset(ht,0,sizeof(HashTable)); ht->array_size = size; ht->Hash = Hash; @@ -115,7 +115,7 @@ int HashTableAdd(HashTable *ht, void *data, uint16_t datalen) { uint32_t hash = ht->Hash(ht, data, datalen); HashTableBucket *hb = SCMalloc(sizeof(HashTableBucket)); - if (hb == NULL) + if (unlikely(hb == NULL)) goto error; memset(hb, 0, sizeof(HashTableBucket)); hb->data = data; diff --git a/src/util-hashlist.c b/src/util-hashlist.c index 6da8e85112..19c209ed2d 100644 --- a/src/util-hashlist.c +++ b/src/util-hashlist.c @@ -47,8 +47,8 @@ HashListTable* HashListTableInit(uint32_t size, uint32_t (*Hash)(struct HashList /* setup the filter */ ht = SCMalloc(sizeof(HashListTable)); - if (ht == NULL) - goto error; + if (unlikely(ht == NULL)) + goto error; memset(ht,0,sizeof(HashListTable)); ht->array_size = size; ht->Hash = Hash; @@ -120,7 +120,7 @@ int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen) { SCLogDebug("ht %p hash %"PRIu32"", ht, hash); HashListTableBucket *hb = SCMalloc(sizeof(HashListTableBucket)); - if (hb == NULL) + if (unlikely(hb == NULL)) goto error; memset(hb, 0, sizeof(HashListTableBucket)); hb->data = data; diff --git a/src/util-mpm-ac-bs.c b/src/util-mpm-ac-bs.c index a9c00d1bc3..44ff034816 100644 --- a/src/util-mpm-ac-bs.c +++ b/src/util-mpm-ac-bs.c @@ -217,7 +217,7 @@ static inline SCACBSPattern *SCACBSInitHashLookup(SCACBSCtx *ctx, uint8_t *pat, static inline SCACBSPattern *SCACBSAllocPattern(MpmCtx *mpm_ctx) { SCACBSPattern *p = SCMalloc(sizeof(SCACBSPattern)); - if (p == NULL) { + if (unlikely(p == NULL)) { exit(EXIT_FAILURE); } memset(p, 0, sizeof(SCACBSPattern)); diff --git a/src/util-mpm-ac-gfbs.c b/src/util-mpm-ac-gfbs.c index abfa86d5c6..0f18c451ea 100644 --- a/src/util-mpm-ac-gfbs.c +++ b/src/util-mpm-ac-gfbs.c @@ -211,7 +211,7 @@ static inline SCACGfbsPattern *SCACGfbsInitHashLookup(SCACGfbsCtx *ctx, uint8_t static inline SCACGfbsPattern *SCACGfbsAllocPattern(MpmCtx *mpm_ctx) { SCACGfbsPattern *p = SCMalloc(sizeof(SCACGfbsPattern)); - if (p == NULL) { + if (unlikely(p == NULL)) { exit(EXIT_FAILURE); } memset(p, 0, sizeof(SCACGfbsPattern)); diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index e6306e2aa6..bde8e914b2 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -217,7 +217,7 @@ static inline SCACPattern *SCACInitHashLookup(SCACCtx *ctx, uint8_t *pat, static inline SCACPattern *SCACAllocPattern(MpmCtx *mpm_ctx) { SCACPattern *p = SCMalloc(sizeof(SCACPattern)); - if (p == NULL) { + if (unlikely(p == NULL)) { exit(EXIT_FAILURE); } memset(p, 0, sizeof(SCACPattern)); diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c index 7c11e51d28..d9416ca492 100644 --- a/src/util-mpm-b2g-cuda.c +++ b/src/util-mpm-b2g-cuda.c @@ -142,7 +142,7 @@ void B2gCudaPrintInfo(MpmCtx *mpm_ctx) static inline B2gCudaPattern *B2gCudaAllocPattern(MpmCtx *mpm_ctx) { B2gCudaPattern *p = SCMalloc(sizeof(B2gCudaPattern)); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p, 0, sizeof(B2gCudaPattern)); @@ -155,7 +155,7 @@ static inline B2gCudaPattern *B2gCudaAllocPattern(MpmCtx *mpm_ctx) static inline B2gCudaHashItem *B2gCudaAllocHashItem(MpmCtx *mpm_ctx) { B2gCudaHashItem *hi = SCMalloc(sizeof(B2gCudaHashItem)); - if (hi == NULL) + if (unlikely(hi == NULL)) return NULL; memset(hi, 0, sizeof(B2gCudaHashItem)); @@ -1700,7 +1700,7 @@ TmEcode B2gCudaMpmDispThreadInit(ThreadVars *tv, void *initdata, void **data) } B2gCudaMpmThreadCtxData *tctx = SCMalloc(sizeof(B2gCudaMpmThreadCtxData)); - if (tctx == NULL) { + if (unlikely(tctx == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -2455,7 +2455,7 @@ static int B2gCudaTest01(void) pb->packets_payload_offset_buffer[0] = 0; p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) goto end; memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); diff --git a/src/util-mpm-b2g.c b/src/util-mpm-b2g.c index 0d7880baed..293f01ee87 100644 --- a/src/util-mpm-b2g.c +++ b/src/util-mpm-b2g.c @@ -133,7 +133,7 @@ void B2gPrintInfo(MpmCtx *mpm_ctx) { */ static inline B2gPattern *B2gAllocPattern(MpmCtx *mpm_ctx) { B2gPattern *p = SCMalloc(sizeof(B2gPattern)); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p,0,sizeof(B2gPattern)); @@ -145,7 +145,7 @@ static inline B2gPattern *B2gAllocPattern(MpmCtx *mpm_ctx) { static inline B2gPattern * B2gAllocHashItem(MpmCtx *mpm_ctx) { B2gPattern *hi = SCMalloc(sizeof(B2gPattern)); - if (hi == NULL) + if (unlikely(hi == NULL)) return NULL; memset(hi,0,sizeof(B2gPattern)); diff --git a/src/util-mpm-b2gc.c b/src/util-mpm-b2gc.c index f68adb69af..f7ab47c979 100644 --- a/src/util-mpm-b2gc.c +++ b/src/util-mpm-b2gc.c @@ -173,7 +173,7 @@ static inline void memcpy_tolower(uint8_t *d, uint8_t *s, uint16_t len) { static inline B2gcPattern *B2gcAllocPattern(MpmCtx *mpm_ctx) { B2gcPattern *p = SCMalloc(sizeof(B2gcPattern)); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p,0,sizeof(B2gcPattern)); diff --git a/src/util-mpm-b2gm.c b/src/util-mpm-b2gm.c index 3c4307761f..9217310178 100644 --- a/src/util-mpm-b2gm.c +++ b/src/util-mpm-b2gm.c @@ -126,7 +126,7 @@ void B2gmPrintInfo(MpmCtx *mpm_ctx) { static inline B2gmPattern *B2gmAllocPattern(MpmCtx *mpm_ctx) { B2gmPattern *p = SCMalloc(sizeof(B2gmPattern)); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p,0,sizeof(B2gmPattern)); @@ -138,7 +138,7 @@ static inline B2gmPattern *B2gmAllocPattern(MpmCtx *mpm_ctx) { static inline B2gmPattern * B2gmAllocHashItem(MpmCtx *mpm_ctx) { B2gmPattern *hi = SCMalloc(sizeof(B2gmPattern)); - if (hi == NULL) + if (unlikely(hi == NULL)) return NULL; memset(hi,0,sizeof(B2gmPattern)); diff --git a/src/util-mpm-b3g.c b/src/util-mpm-b3g.c index 4a45f5bac3..73985e8c1c 100644 --- a/src/util-mpm-b3g.c +++ b/src/util-mpm-b3g.c @@ -105,7 +105,7 @@ void B3gPrintInfo(MpmCtx *mpm_ctx) { static inline B3gPattern *B3gAllocPattern(MpmCtx *mpm_ctx) { B3gPattern *p = SCMalloc(sizeof(B3gPattern)); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p,0,sizeof(B3gPattern)); @@ -117,7 +117,7 @@ static inline B3gPattern *B3gAllocPattern(MpmCtx *mpm_ctx) { static inline B3gHashItem * B3gAllocHashItem(MpmCtx *mpm_ctx) { B3gHashItem *hi = SCMalloc(sizeof(B3gHashItem)); - if (hi == NULL) + if (unlikely(hi == NULL)) return NULL; memset(hi,0,sizeof(B3gHashItem)); diff --git a/src/util-mpm-wumanber.c b/src/util-mpm-wumanber.c index 5b19c82c45..9ecf8237ec 100644 --- a/src/util-mpm-wumanber.c +++ b/src/util-mpm-wumanber.c @@ -136,7 +136,7 @@ void WmPrintInfo(MpmCtx *mpm_ctx) { static inline WmPattern *WmAllocPattern(MpmCtx *mpm_ctx) { WmPattern *p = SCMalloc(sizeof(WmPattern)); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p,0,sizeof(WmPattern)); @@ -148,7 +148,7 @@ static inline WmPattern *WmAllocPattern(MpmCtx *mpm_ctx) { static inline WmHashItem * WmAllocHashItem(MpmCtx *mpm_ctx) { WmHashItem *hi = SCMalloc(sizeof(WmHashItem)); - if (hi == NULL) + if (unlikely(hi == NULL)) return NULL; memset(hi,0,sizeof(WmHashItem)); diff --git a/src/util-mpm.c b/src/util-mpm.c index bca6789f35..64a0c633d2 100644 --- a/src/util-mpm.c +++ b/src/util-mpm.c @@ -67,7 +67,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *nam memset(de_ctx->mpm_ctx_factory_container, 0, sizeof(MpmCtxFactoryContainer)); MpmCtxFactoryItem *item = SCMalloc(sizeof(MpmCtxFactoryItem)); - if (item == NULL) { + if (unlikely(item == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -205,7 +205,7 @@ MpmCtx *MpmFactoryGetMpmCtxForProfile(DetectEngineCtx *de_ctx, int32_t id, int d { if (id == MPM_CTX_FACTORY_UNIQUE_CONTEXT) { MpmCtx *mpm_ctx = SCMalloc(sizeof(MpmCtx)); - if (mpm_ctx == NULL) { + if (unlikely(mpm_ctx == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } diff --git a/src/util-pool.c b/src/util-pool.c index 581824f9d2..7a3d775e4c 100644 --- a/src/util-pool.c +++ b/src/util-pool.c @@ -93,7 +93,7 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * /* setup the filter */ p = SCMalloc(sizeof(Pool)); - if (p == NULL) + if (unlikely(p == NULL)) goto error; memset(p,0,sizeof(Pool)); @@ -140,7 +140,7 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * for (u32 = 0; u32 < prealloc_size; u32++) { if (size == 0) { /* unlimited */ PoolBucket *pb = SCMalloc(sizeof(PoolBucket)); - if (pb == NULL) + if (unlikely(pb == NULL)) goto error; memset(pb, 0, sizeof(PoolBucket)); @@ -350,7 +350,7 @@ void PoolPrintSaturation(Pool *p) { void *PoolTestAlloc() { void *ptr = SCMalloc(10); - if (ptr == NULL) + if (unlikely(ptr == NULL)) return NULL; return ptr; } diff --git a/src/util-profiling-rules.c b/src/util-profiling-rules.c index 086db4af87..4b7c3c7615 100644 --- a/src/util-profiling-rules.c +++ b/src/util-profiling-rules.c @@ -168,7 +168,7 @@ void SCProfilingRulesGlobalInit(void) { log_dir = DEFAULT_LOG_DIR; profiling_file_name = SCMalloc(PATH_MAX); - if (profiling_file_name == NULL) { + if (unlikely(profiling_file_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name"); exit(EXIT_FAILURE); } @@ -289,7 +289,7 @@ SCProfilingRuleDump(SCProfileDetectCtx *rules_ctx) int summary_size = sizeof(SCProfileSummary) * rules_ctx->size; SCProfileSummary *summary = SCMalloc(summary_size); - if (summary == NULL) { + if (unlikely(summary == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for profiling summary"); return; } diff --git a/src/util-profiling.c b/src/util-profiling.c index ee54a5dd2f..397063a5e9 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -141,7 +141,7 @@ SCProfilingInit(void) log_dir = DEFAULT_LOG_DIR; profiling_packets_file_name = SCMalloc(PATH_MAX); - if (profiling_packets_file_name == NULL) { + if (unlikely(profiling_packets_file_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name"); exit(EXIT_FAILURE); } @@ -173,7 +173,7 @@ SCProfilingInit(void) log_dir = DEFAULT_LOG_DIR; profiling_csv_file_name = SCMalloc(PATH_MAX); - if (profiling_csv_file_name == NULL) { + if (unlikely(profiling_csv_file_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "out of memory"); exit(EXIT_FAILURE); } @@ -220,7 +220,7 @@ SCProfilingInit(void) log_dir = DEFAULT_LOG_DIR; profiling_locks_file_name = SCMalloc(PATH_MAX); - if (profiling_locks_file_name == NULL) { + if (unlikely(profiling_locks_file_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name"); exit(EXIT_FAILURE); } diff --git a/src/util-radix-tree.c b/src/util-radix-tree.c index 2d12d1759b..e57f8aaf1b 100644 --- a/src/util-radix-tree.c +++ b/src/util-radix-tree.c @@ -128,7 +128,7 @@ void SCRadixChopIPAddressAgainstNetmask(uint8_t *stream, uint8_t netmask, static SCRadixUserData *SCRadixAllocSCRadixUserData(uint8_t netmask, void *user) { SCRadixUserData *user_data = SCMalloc(sizeof(SCRadixUserData)); - if (user_data == NULL) { + if (unlikely(user_data == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); return NULL; } @@ -3183,7 +3183,7 @@ int SCRadixTestIPV4NetBlocksAndBestSearch15(void) for (; i <= 32; i++) { user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3242,7 +3242,7 @@ int SCRadixTestIPV4NetBlocksAndBestSearch16(void) for (; i <= 32; i++) { user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3301,7 +3301,7 @@ int SCRadixTestIPV4NetBlocksAndBestSearch17(void) for (; i <= 32; i++) { user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3360,7 +3360,7 @@ int SCRadixTestIPV4NetBlocksAndBestSearch18(void) for (; i <= 32; i++) { user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3416,7 +3416,7 @@ int SCRadixTestIPV4NetBlocksAndBestSearch19(void) } user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3456,7 +3456,7 @@ int SCRadixTestIPV4NetBlocksAndBestSearch19(void) } user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3520,7 +3520,7 @@ int SCRadixTestIPV4NetBlocksAndBestSearch19(void) } user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3656,7 +3656,7 @@ int SCRadixTestIPV6NetBlocksAndBestSearch20(void) for (; i <= 128; i++) { user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3715,7 +3715,7 @@ int SCRadixTestIPV6NetBlocksAndBestSearch21(void) for (; i <= 128; i++) { user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3774,7 +3774,7 @@ int SCRadixTestIPV6NetBlocksAndBestSearch22(void) for (; i <= 128; i++) { user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3833,7 +3833,7 @@ int SCRadixTestIPV6NetBlocksAndBestSearch23(void) for (; i <= 128; i++) { user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3889,7 +3889,7 @@ int SCRadixTestIPV6NetBlocksAndBestSearch24(void) } user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3929,7 +3929,7 @@ int SCRadixTestIPV6NetBlocksAndBestSearch24(void) } user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -3995,7 +3995,7 @@ int SCRadixTestIPV6NetBlocksAndBestSearch24(void) } user = SCMalloc(sizeof(uint32_t)); - if (user == NULL) { + if (unlikely(user == NULL)) { result = 0; goto end; } @@ -4203,7 +4203,7 @@ this_end: static int SCRadixTestUserdataMacro01(void) { int result = 0; SCRadixNode *node = SCMalloc(sizeof(SCRadixNode)); - if (node == NULL) { + if (unlikely(node == NULL)) { goto end; } memset(node, 0x00, sizeof(*node)); @@ -4228,7 +4228,7 @@ static int SCRadixTestUserdataMacro02(void) { SCRadixPrefix prefix; int result = 0; SCRadixNode *node = SCMalloc(sizeof(SCRadixNode)); - if (node == NULL) { + if (unlikely(node == NULL)) { goto end; } memset(node, 0x00, sizeof(*node)); @@ -4257,7 +4257,7 @@ static int SCRadixTestUserdataMacro03(void) { int result = 0; void *somep = &result; SCRadixNode *node = SCMalloc(sizeof(SCRadixNode)); - if (node == NULL) { + if (unlikely(node == NULL)) { goto end; } memset(node, 0x00, sizeof(*node)); diff --git a/src/util-ringbuffer.c b/src/util-ringbuffer.c index 271493a73c..82ed320965 100644 --- a/src/util-ringbuffer.c +++ b/src/util-ringbuffer.c @@ -486,7 +486,7 @@ int RingBufferSrSwPut(RingBuffer16 *rb, void *ptr) { RingBuffer8 *RingBuffer8Init(void) { RingBuffer8 *rb = SCMalloc(sizeof(RingBuffer8)); - if (rb == NULL) { + if (unlikely(rb == NULL)) { return NULL; } @@ -619,7 +619,7 @@ retry: RingBuffer16 *RingBufferInit(void) { RingBuffer16 *rb = SCMalloc(sizeof(RingBuffer16)); - if (rb == NULL) { + if (unlikely(rb == NULL)) { return NULL; } diff --git a/src/util-rohash.c b/src/util-rohash.c index 008b597b4c..ce1e13cb3b 100644 --- a/src/util-rohash.c +++ b/src/util-rohash.c @@ -74,7 +74,7 @@ ROHashTable *ROHashInit(uint8_t hash_bits, uint16_t item_size) { uint32_t size = hashsize(hash_bits) * sizeof(ROHashTableOffsets); ROHashTable *table = SCMalloc(sizeof(ROHashTable) + size); - if (table == NULL) { + if (unlikely(table == NULL)) { SCLogError(SC_ERR_HASH_TABLE_INIT, "failed to alloc memory"); return NULL; } diff --git a/src/util-runmodes.c b/src/util-runmodes.c index 68ff4cb81d..1fa9d1df3d 100644 --- a/src/util-runmodes.c +++ b/src/util-runmodes.c @@ -132,7 +132,7 @@ int RunModeSetLiveCaptureAuto(DetectEngineCtx *de_ctx, snprintf(tname, sizeof(tname),"%s-%s", thread_name, live_dev); tnamec = SCStrdup(tname); - if (tnamec == NULL) { + if (unlikely(tnamec == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate thread name"); exit(EXIT_FAILURE); } @@ -311,7 +311,7 @@ int RunModeSetLiveCaptureAuto(DetectEngineCtx *de_ctx, char *thread_name = SCStrdup(tname); - if (thread_name == NULL) { + if (unlikely(thread_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate thread name"); exit(EXIT_FAILURE); } @@ -336,7 +336,7 @@ int RunModeSetLiveCaptureAuto(DetectEngineCtx *de_ctx, TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET); char *thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { + if (unlikely(thread_group_name == NULL)) { SCLogError(SC_ERR_RUNMODE, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -444,7 +444,7 @@ int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx, for (thread = 0; thread < threads_count; thread++) { snprintf(tname, sizeof(tname), "%s%"PRIu16, thread_name, thread+1); char *thread_name = SCStrdup(tname); - if (thread_name == NULL) { + if (unlikely(thread_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate thread name"); exit(EXIT_FAILURE); } @@ -507,7 +507,7 @@ int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx, snprintf(tname, sizeof(tname), "%s%s%"PRIu16, thread_name, live_dev, thread+1); char *thread_name = SCStrdup(tname); - if (thread_name == NULL) { + if (unlikely(thread_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate thread name"); exit(EXIT_FAILURE); } @@ -550,7 +550,7 @@ int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx, SCLogDebug("tname %s, qname %s", tname, qname); char *thread_name = SCStrdup(tname); - if (thread_name == NULL) { + if (unlikely(thread_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate thread name"); exit(EXIT_FAILURE); } @@ -581,7 +581,7 @@ int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx, TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET); char *thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { + if (unlikely(thread_group_name == NULL)) { SCLogError(SC_ERR_RUNMODE, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -637,7 +637,7 @@ static int RunModeSetLiveCaptureWorkersForDevice(DetectEngineCtx *de_ctx, thread_name, live_dev, thread+1); } n_thread_name = SCStrdup(tname); - if (n_thread_name == NULL) { + if (unlikely(n_thread_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate thread name"); exit(EXIT_FAILURE); } @@ -715,7 +715,7 @@ int RunModeSetLiveCaptureWorkers(DetectEngineCtx *de_ctx, if (live_dev != NULL) { aconf = ConfigParser(live_dev); live_dev_c = SCStrdup(live_dev); - if (live_dev_c == NULL) { + if (unlikely(live_dev_c == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate interface name"); exit(EXIT_FAILURE); } @@ -896,7 +896,7 @@ int RunModeSetIPSAuto(DetectEngineCtx *de_ctx, TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET); char *thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { + if (unlikely(thread_group_name == NULL)) { printf("Error allocating memory\n"); exit(EXIT_FAILURE); } @@ -1058,7 +1058,7 @@ int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx, SCLogDebug("tname %s, qname %s", tname, qname); char *thread_name = SCStrdup(tname); - if (thread_name == NULL) { + if (unlikely(thread_name == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate thread name"); exit(EXIT_FAILURE); } @@ -1091,7 +1091,7 @@ int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx, SetupOutputs(tv_detect_ncpu); char *thread_group_name = SCStrdup("Detect"); - if (thread_group_name == NULL) { + if (unlikely(thread_group_name == NULL)) { SCLogError(SC_ERR_RUNMODE, "Error allocating memory"); exit(EXIT_FAILURE); } diff --git a/src/util-spm-bm.c b/src/util-spm-bm.c index b4aa11d2cd..ca7c82d65a 100644 --- a/src/util-spm-bm.c +++ b/src/util-spm-bm.c @@ -64,7 +64,7 @@ void BoyerMooreCtxToNocase(BmCtx *bm_ctx, uint8_t *needle, uint16_t needle_len) */ BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint16_t needle_len) { BmCtx *new = SCMalloc(sizeof(BmCtx)); - if (new == NULL) { + if (unlikely(new == NULL)) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in BoyerMooreCtxInit. Exiting..."); exit(EXIT_FAILURE); } @@ -162,7 +162,7 @@ int PreBmGs(const uint8_t *x, uint16_t m, uint16_t *bmGs) { uint16_t *suff; suff = SCMalloc(sizeof(uint16_t) * (m + 1)); - if (suff == NULL) + if (unlikely(suff == NULL)) return -1; BoyerMooreSuffixes(x, m, suff); @@ -237,7 +237,7 @@ void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs) { uint16_t* suff; suff = SCMalloc(sizeof(uint16_t) * (m + 1)); - if (suff == NULL) + if (unlikely(suff == NULL)) return; BoyerMooreSuffixesNocase(x, m, suff); diff --git a/src/util-spm.c b/src/util-spm.c index d83fc37780..9f115da05a 100644 --- a/src/util-spm.c +++ b/src/util-spm.c @@ -102,7 +102,7 @@ uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uin uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) { uint16_t bmBc[ALPHABET_SIZE]; uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); - if (bmGs == NULL) + if (unlikely(bmGs == NULL)) return NULL; PreBmGs(needle, needlelen, bmGs); @@ -126,7 +126,7 @@ uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) { uint16_t bmBc[ALPHABET_SIZE]; uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); - if (bmGs == NULL) + if (unlikely(bmGs == NULL)) return NULL; PreBmGsNocase(needle, needlelen, bmGs); @@ -234,7 +234,7 @@ uint8_t *BoyerMooreWrapper(uint8_t *text, uint8_t *needle, int times) { uint16_t bmBc[ALPHABET_SIZE]; uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); - if (bmGs == NULL) + if (unlikely(bmGs == NULL)) return NULL; uint8_t *ret = NULL; @@ -259,7 +259,7 @@ uint8_t *BoyerMooreNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { uint16_t bmBc[ALPHABET_SIZE]; uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); - if (bmGs == NULL) + if (unlikely(bmGs == NULL)) return NULL; uint8_t *ret = NULL; @@ -366,7 +366,7 @@ uint8_t *BoyerMooreCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint16_t bmBc[ALPHABET_SIZE]; uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); - if (bmGs == NULL) + if (unlikely(bmGs == NULL)) return NULL; uint8_t *ret = NULL; @@ -408,7 +408,7 @@ uint8_t *BoyerMooreNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint16_t bmBc[ALPHABET_SIZE]; uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); - if (bmGs == NULL) + if (unlikely(bmGs == NULL)) return NULL; uint8_t *ret = NULL; diff --git a/src/util-threshold-config.c b/src/util-threshold-config.c index 3b942fa8d9..c6fe1ed5e0 100644 --- a/src/util-threshold-config.c +++ b/src/util-threshold-config.c @@ -584,7 +584,7 @@ int SCThresholdConfAddThresholdtype(char *rawstr, DetectEngineCtx *de_ctx) } de = SCMalloc(sizeof(DetectThresholdData)); - if (de == NULL) + if (unlikely(de == NULL)) goto error; memset(de,0,sizeof(DetectThresholdData)); @@ -665,7 +665,7 @@ int SCThresholdConfAddThresholdtype(char *rawstr, DetectEngineCtx *de_ctx) } de = SCMalloc(sizeof(DetectThresholdData)); - if (de == NULL) + if (unlikely(de == NULL)) goto error; memset(de,0,sizeof(DetectThresholdData)); @@ -753,7 +753,7 @@ int SCThresholdConfAddThresholdtype(char *rawstr, DetectEngineCtx *de_ctx) } de = SCMalloc(sizeof(DetectThresholdData)); - if (de == NULL) + if (unlikely(de == NULL)) goto error; memset(de,0,sizeof(DetectThresholdData)); diff --git a/src/util-unittest-helper.c b/src/util-unittest-helper.c index b64f2924a7..03bd7aad20 100644 --- a/src/util-unittest-helper.c +++ b/src/util-unittest-helper.c @@ -79,7 +79,7 @@ Packet *UTHBuildPacketIPV6Real(uint8_t *payload, uint16_t payload_len, uint32_t in[4]; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); @@ -166,7 +166,7 @@ Packet *UTHBuildPacketReal(uint8_t *payload, uint16_t payload_len, struct in_addr in; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p, 0, SIZE_OF_PACKET); p->pkt = ((uint8_t *)p) + sizeof(*p); @@ -282,7 +282,7 @@ Packet **UTHBuildPacketArrayFromEth(uint8_t *raw_eth[], int *pktsize, int numpkt } Packet **p = NULL; p = SCMalloc(sizeof(Packet *) * numpkts); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(&dtv, 0, sizeof(DecodeThreadVars)); @@ -315,7 +315,7 @@ Packet *UTHBuildPacketFromEth(uint8_t *raw_eth, uint16_t pktsize) { DecodeThreadVars dtv; ThreadVars th_v; Packet *p = SCMalloc(SIZE_OF_PACKET); - if (p == NULL) + if (unlikely(p == NULL)) return NULL; memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); @@ -430,8 +430,9 @@ Flow *UTHBuildFlow(int family, char *src, char *dst, Port sp, Port dp) { struct in_addr in; Flow *f = SCMalloc(sizeof(Flow)); - if (f == NULL) { - printf("FlowAlloc failed\n");; + if (unlikely(f == NULL)) { + printf("FlowAlloc failed\n"); + ; return NULL; } memset(f, 0x00, sizeof(Flow)); diff --git a/src/util-unittest.c b/src/util-unittest.c index d44cff4af7..4381bcfd53 100644 --- a/src/util-unittest.c +++ b/src/util-unittest.c @@ -46,7 +46,7 @@ static UtTest *ut_list; static UtTest *UtAllocTest(void) { UtTest *ut = SCMalloc(sizeof(UtTest)); - if (ut == NULL) + if (unlikely(ut == NULL)) return NULL; memset(ut, 0, sizeof(UtTest)); diff --git a/src/util-var-name.c b/src/util-var-name.c index cbad0a1c39..d14938237e 100644 --- a/src/util-var-name.c +++ b/src/util-var-name.c @@ -134,7 +134,7 @@ uint16_t VariableNameGetIdx(DetectEngineCtx *de_ctx, char *name, uint8_t type) { uint16_t idx = 0; VariableName *fn = SCMalloc(sizeof(VariableName)); - if (fn == NULL) + if (unlikely(fn == NULL)) goto error; memset(fn, 0, sizeof(VariableName)); @@ -171,7 +171,7 @@ error: char *VariableIdxGetName(DetectEngineCtx *de_ctx, uint16_t idx, uint8_t type) { VariableName *fn = SCMalloc(sizeof(VariableName)); - if (fn == NULL) + if (unlikely(fn == NULL)) goto error; char *name = NULL; @@ -183,7 +183,7 @@ char *VariableIdxGetName(DetectEngineCtx *de_ctx, uint16_t idx, uint8_t type) VariableName *lookup_fn = (VariableName *)HashListTableLookup(de_ctx->variable_idxs, (void *)fn, 0); if (lookup_fn != NULL) { name = SCStrdup(lookup_fn->name); - if (name == NULL) + if (unlikely(name == NULL)) goto error; VariableNameFree(fn); diff --git a/src/win32-misc.c b/src/win32-misc.c index 83f86aa8b5..8014c8fb13 100644 --- a/src/win32-misc.c +++ b/src/win32-misc.c @@ -33,7 +33,7 @@ void setenv(const char *name, const char *value, int overwrite) { if (overwrite || NULL == getenv(name)) { char *str = SCMalloc(strlen(name) + strlen(value) + 2); - if (str == NULL) + if (unlikely(str == NULL)) return; snprintf(str, strlen(name) + strlen(value) + 1, "%s=%s", name, value); putenv(str); @@ -44,7 +44,7 @@ void setenv(const char *name, const char *value, int overwrite) void unsetenv(const char *name) { char *str = SCMalloc(strlen(name) + 2); - if (str == NULL) + if (unlikely(str == NULL)) return; snprintf(str, strlen(name) + 1, "%s=", name); putenv(str); -- 2.47.3