From: Victor Julien Date: Mon, 24 Oct 2022 10:57:29 +0000 (+0200) Subject: error: use SC_ENOMEM for alloc errors X-Git-Tag: suricata-7.0.0-rc1~231 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e042cd785e93bb862dafb1c0edef4a338fcc18d0;p=thirdparty%2Fsuricata.git error: use SC_ENOMEM for alloc errors --- diff --git a/src/conf.c b/src/conf.c index 671da0f808..d674fdd647 100644 --- a/src/conf.c +++ b/src/conf.c @@ -84,16 +84,14 @@ static ConfNode *ConfGetNodeOrCreate(const char *name, int final) if ((node = ConfNodeLookupChild(parent, key)) == NULL) { node = ConfNodeNew(); if (unlikely(node == NULL)) { - SCLogWarning(SC_ERR_MEM_ALLOC, - "Failed to allocate memory for configuration."); + SCLogWarning(SC_ENOMEM, "Failed to allocate memory for configuration."); goto end; } node->name = SCStrdup(key); if (unlikely(node->name == NULL)) { ConfNodeFree(node); node = NULL; - SCLogWarning(SC_ERR_MEM_ALLOC, - "Failed to allocate memory for configuration."); + SCLogWarning(SC_ENOMEM, "Failed to allocate memory for configuration."); goto end; } node->parent = parent; diff --git a/src/counters.c b/src/counters.c index 18d7e19509..33ebbe43c7 100644 --- a/src/counters.c +++ b/src/counters.c @@ -661,7 +661,7 @@ static int StatsOutput(ThreadVars *tv) stats_table.stats = SCCalloc(stats_table.nstats, sizeof(StatsRecord)); if (stats_table.stats == NULL) { stats_table.nstats = 0; - SCLogError(SC_ERR_MEM_ALLOC, "could not alloc memory for stats"); + SCLogError(SC_ENOMEM, "could not alloc memory for stats"); return -1; } @@ -670,7 +670,7 @@ static int StatsOutput(ThreadVars *tv) stats_table.tstats = SCCalloc(stats_table.ntstats, array_size); if (stats_table.tstats == NULL) { stats_table.ntstats = 0; - SCLogError(SC_ERR_MEM_ALLOC, "could not alloc memory for stats"); + SCLogError(SC_ENOMEM, "could not alloc memory for stats"); return -1; } diff --git a/src/detect-dsize.c b/src/detect-dsize.c index d2eb12fcb7..ccbd0c0fdc 100644 --- a/src/detect-dsize.c +++ b/src/detect-dsize.c @@ -139,7 +139,7 @@ static int DetectDsizeSetup (DetectEngineCtx *de_ctx, Signature *s, const char * * and put it in the Signature. */ sm = SigMatchAlloc(); if (sm == NULL){ - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for SigMatch"); + SCLogError(SC_ENOMEM, "Failed to allocate memory for SigMatch"); rs_detect_u16_free(dd); goto error; } diff --git a/src/detect-engine-alert.c b/src/detect-engine-alert.c index b9440b8abf..aae6d5a073 100644 --- a/src/detect-engine-alert.c +++ b/src/detect-engine-alert.c @@ -224,7 +224,7 @@ void AlertQueueInit(DetectEngineThreadCtx *det_ctx) det_ctx->alert_queue_size = 0; det_ctx->alert_queue = SCCalloc(packet_alert_max, sizeof(PacketAlert)); if (det_ctx->alert_queue == NULL) { - FatalError(SC_ERR_MEM_ALLOC, "failed to allocate %" PRIu64 " bytes for the alert queue", + FatalError(SC_ENOMEM, "failed to allocate %" PRIu64 " bytes for the alert queue", (uint64_t)(packet_alert_max * sizeof(PacketAlert))); } det_ctx->alert_queue_capacity = packet_alert_max; diff --git a/src/detect-engine-loader.c b/src/detect-engine-loader.c index 9e1d39bd4d..1451e28751 100644 --- a/src/detect-engine-loader.c +++ b/src/detect-engine-loader.c @@ -192,8 +192,10 @@ static int DetectLoadSigFile(DetectEngineCtx *de_ctx, char *sig_file, "file %s at line %"PRId32"", line, sig_file, lineno - multiline); if (!SigStringAppend(&de_ctx->sig_stat, sig_file, line, de_ctx->sigerror, (lineno - multiline))) { - SCLogError(SC_ERR_MEM_ALLOC, "Error adding sig \"%s\" from " - "file %s at line %"PRId32"", line, sig_file, lineno - multiline); + SCLogError(SC_ENOMEM, + "Error adding sig \"%s\" from " + "file %s at line %" PRId32 "", + line, sig_file, lineno - multiline); } if (de_ctx->sigerror) { de_ctx->sigerror = NULL; diff --git a/src/detect-engine-threshold.c b/src/detect-engine-threshold.c index c007197c07..3190550fcf 100644 --- a/src/detect-engine-threshold.c +++ b/src/detect-engine-threshold.c @@ -717,7 +717,7 @@ void ThresholdHashAllocate(DetectEngineCtx *de_ctx) de_ctx->ths_ctx.th_size = highest_signum + 1; de_ctx->ths_ctx.th_entry = SCCalloc(de_ctx->ths_ctx.th_size, sizeof(DetectThresholdEntry *)); if (de_ctx->ths_ctx.th_entry == NULL) { - FatalError(SC_ERR_MEM_ALLOC, + FatalError(SC_ENOMEM, "Error allocating memory for rule " "thresholds (tried to allocate %" PRIu32 " th_entrys for " "rule tracking)", diff --git a/src/detect-filemagic.c b/src/detect-filemagic.c index b30414a1aa..4979f3b627 100644 --- a/src/detect-filemagic.c +++ b/src/detect-filemagic.c @@ -325,7 +325,7 @@ static void *DetectFilemagicThreadInit(void *data /*@unused@*/) { DetectFilemagicThreadData *t = SCCalloc(1, sizeof(DetectFilemagicThreadData)); if (unlikely(t == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "couldn't alloc ctx memory"); + SCLogError(SC_ENOMEM, "couldn't alloc ctx memory"); return NULL; } diff --git a/src/detect-flowbits.c b/src/detect-flowbits.c index 1d0bea34cf..839753fce6 100644 --- a/src/detect-flowbits.c +++ b/src/detect-flowbits.c @@ -417,7 +417,7 @@ int DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx) struct FBAnalyze *array = SCCalloc(array_size, sizeof(struct FBAnalyze)); if (array == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate flowbit analyze array"); + SCLogError(SC_ENOMEM, "Unable to allocate flowbit analyze array"); return -1; } diff --git a/src/detect-flowint.c b/src/detect-flowint.c index 3819747cd1..faf4a2bb29 100644 --- a/src/detect-flowint.c +++ b/src/detect-flowint.c @@ -317,7 +317,7 @@ static DetectFlowintData *DetectFlowintParse(DetectEngineCtx *de_ctx, const char sfd->targettype = FLOWINT_TARGET_VAR; sfd->target.tvar.name = SCStrdup(varval); if (unlikely(sfd->target.tvar.name == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "malloc from strdup failed"); + SCLogError(SC_ENOMEM, "malloc from strdup failed"); goto error; } } @@ -328,7 +328,7 @@ static DetectFlowintData *DetectFlowintParse(DetectEngineCtx *de_ctx, const char /* Set the name of the origin var to modify/compared with the target */ sfd->name = SCStrdup(varname); if (unlikely(sfd->name == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "malloc from strdup failed"); + SCLogError(SC_ENOMEM, "malloc from strdup failed"); goto error; } sfd->idx = VarNameStoreSetupAdd(varname, VAR_TYPE_FLOW_INT); diff --git a/src/detect-metadata.c b/src/detect-metadata.c index c311c1a155..de21328d03 100644 --- a/src/detect-metadata.c +++ b/src/detect-metadata.c @@ -207,13 +207,13 @@ static int DetectMetadataParse(DetectEngineCtx *de_ctx, Signature *s, const char const char *hkey = DetectMedatataHashAdd(de_ctx, key); if (hkey == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "can't create metadata key"); + SCLogError(SC_ENOMEM, "can't create metadata key"); continue; } const char *hval = DetectMedatataHashAdd(de_ctx, val); if (hval == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "can't create metadata value"); + SCLogError(SC_ENOMEM, "can't create metadata value"); goto next; } diff --git a/src/detect-parse.c b/src/detect-parse.c index dca3b3e06d..e218438fb9 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -324,7 +324,7 @@ void SigTableApplyStrictCommandlineOption(const char *str) char *copy = SCStrdup(str); if (copy == NULL) - FatalError(SC_ERR_MEM_ALLOC, "could not duplicate opt string"); + FatalError(SC_ENOMEM, "could not duplicate opt string"); char *xsaveptr = NULL; char *key = strtok_r(copy, ",", &xsaveptr); @@ -2525,7 +2525,7 @@ void DetectParseRegexAddToFreeList(DetectParseRegex *detect_parse) { DetectParseRegex *r = SCCalloc(1, sizeof(*r)); if (r == NULL) { - FatalError(SC_ERR_MEM_ALLOC, "failed to alloc memory for pcre free list"); + FatalError(SC_ENOMEM, "failed to alloc memory for pcre free list"); } r->regex = detect_parse->regex; r->match = detect_parse->match; diff --git a/src/detect-reference.c b/src/detect-reference.c index cbcda0c09c..458b4ddc2a 100644 --- a/src/detect-reference.c +++ b/src/detect-reference.c @@ -155,7 +155,7 @@ static DetectReference *DetectReferenceParse(const char *rawstr, DetectEngineCtx /* make a copy so we can free pcre's substring */ ref->reference = SCStrdup(content); if (ref->reference == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "strdup failed: %s", strerror(errno)); + SCLogError(SC_ENOMEM, "strdup failed: %s", strerror(errno)); goto error; } diff --git a/src/detect-tag.c b/src/detect-tag.c index b3c4d8d429..c9e0a4dbdd 100644 --- a/src/detect-tag.c +++ b/src/detect-tag.c @@ -262,7 +262,7 @@ static DetectTagData *DetectTagParse(const char *tagstr) DetectTagData *real_td = SCMalloc(sizeof(DetectTagData)); if (unlikely(real_td == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + SCLogError(SC_ENOMEM, "Error allocating memory"); goto error; } diff --git a/src/detect-transform-xor.c b/src/detect-transform-xor.c index 53c70eda47..27c7106aad 100644 --- a/src/detect-transform-xor.c +++ b/src/detect-transform-xor.c @@ -81,7 +81,7 @@ static int DetectTransformXorSetup(DetectEngineCtx *de_ctx, Signature *s, const // Create pxd from optstr DetectTransformXorData *pxd = SCCalloc(1, sizeof(*pxd)); if (pxd == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "memory allocation failed"); + SCLogError(SC_ENOMEM, "memory allocation failed"); SCReturnInt(-1); } @@ -99,7 +99,7 @@ static int DetectTransformXorSetup(DetectEngineCtx *de_ctx, Signature *s, const pxd->length = (uint8_t)(keylen / 2); pxd->key = SCMalloc(keylen / 2); if (pxd->key == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "memory allocation failed"); + SCLogError(SC_ENOMEM, "memory allocation failed"); DetectTransformXorFree(de_ctx, pxd); SCReturnInt(-1); } diff --git a/src/detect.c b/src/detect.c index 083af5c87a..7345e8d466 100644 --- a/src/detect.c +++ b/src/detect.c @@ -970,7 +970,7 @@ void RuleMatchCandidateTxArrayInit(DetectEngineThreadCtx *det_ctx, uint32_t size DEBUG_VALIDATE_BUG_ON(det_ctx->tx_candidates); det_ctx->tx_candidates = SCCalloc(size, sizeof(RuleMatchCandidateTx)); if (det_ctx->tx_candidates == NULL) { - FatalError(SC_ERR_MEM_ALLOC, "failed to allocate %"PRIu64" bytes", + FatalError(SC_ENOMEM, "failed to allocate %" PRIu64 " bytes", (uint64_t)(size * sizeof(RuleMatchCandidateTx))); } det_ctx->tx_candidates_size = size; @@ -1000,7 +1000,7 @@ static int RuleMatchCandidateTxArrayExpand(DetectEngineThreadCtx *det_ctx, const uint32_t new_size = needed; void *ptmp = SCRealloc(det_ctx->tx_candidates, (new_size * sizeof(RuleMatchCandidateTx))); if (ptmp == NULL) { - FatalError(SC_ERR_MEM_ALLOC, "failed to expand to %"PRIu64" bytes", + FatalError(SC_ENOMEM, "failed to expand to %" PRIu64 " bytes", (uint64_t)(new_size * sizeof(RuleMatchCandidateTx))); // TODO can this be handled more gracefully? } diff --git a/src/feature.c b/src/feature.c index 8505d9c0f6..359e7e519f 100644 --- a/src/feature.c +++ b/src/feature.c @@ -85,7 +85,7 @@ static void FeatureInit(void) { FeatureHashFreeFunc); if (!feature_hash_table) { - FatalError(SC_ERR_MEM_ALLOC, "Unable to allocate feature hash table."); + FatalError(sc_errno, "Unable to allocate feature hash table."); } } @@ -95,7 +95,7 @@ static void FeatureAddEntry(const char *feature_name) FeatureEntryType *feature = SCCalloc(1, sizeof(*feature)); if (!feature) { - FatalError(SC_ERR_MEM_ALLOC, "Unable to allocate feature entry memory."); + FatalError(SC_ENOMEM, "Unable to allocate feature entry memory."); } feature->feature = SCStrdup(feature_name); diff --git a/src/log-cf-common.c b/src/log-cf-common.c index 891dfdc00e..fbe76b1a9b 100644 --- a/src/log-cf-common.c +++ b/src/log-cf-common.c @@ -40,7 +40,7 @@ LogCustomFormatNode * LogCustomFormatNodeAlloc() { LogCustomFormatNode * node = SCCalloc(1, sizeof(LogCustomFormatNode)); if (unlikely(node == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to alloc custom format node"); + SCLogError(SC_ENOMEM, "Failed to alloc custom format node"); return NULL; } return node; @@ -55,7 +55,7 @@ LogCustomFormat * LogCustomFormatAlloc() { LogCustomFormat * cf = SCCalloc(1, sizeof(LogCustomFormat)); if (unlikely(cf == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to alloc custom format"); + SCLogError(SC_ENOMEM, "Failed to alloc custom format"); return NULL; } return cf; diff --git a/src/log-pcap.c b/src/log-pcap.c index e1d8d65c4c..8f9d810ff2 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -784,16 +784,14 @@ static PcapLogData *PcapLogDataCopy(const PcapLogData *pl) copy_comp->buffer = SCMalloc(copy_comp->buffer_size); if (copy_comp->buffer == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s", - strerror(errno)); + SCLogError(SC_ENOMEM, "SCMalloc failed: %s", strerror(errno)); SCFree(copy->h); SCFree(copy); return NULL; } copy_comp->pcap_buf = SCMalloc(copy_comp->pcap_buf_size); if (copy_comp->pcap_buf == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s", - strerror(errno)); + SCLogError(SC_ENOMEM, "SCMalloc failed: %s", strerror(errno)); SCFree(copy_comp->buffer); SCFree(copy->h); SCFree(copy); @@ -1191,7 +1189,7 @@ static void PcapLogDataFree(PcapLogData *pl) LZ4F_errorCode_t errcode = LZ4F_freeCompressionContext(pl->compression.lz4f_context); if (LZ4F_isError(errcode)) { - SCLogWarning(SC_ERR_MEM_ALLOC, "Error freeing lz4 context."); + SCLogWarning(SC_EINVAL, "Error freeing lz4 context."); } } #endif /* HAVE_LIBLZ4 */ @@ -1515,8 +1513,7 @@ static OutputInitResult PcapLogInitCtx(ConfNode *conf) sizeof(struct pcap_pkthdr) + PCAP_SNAPLEN; comp->pcap_buf = SCMalloc(comp->pcap_buf_size); if (comp->pcap_buf == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s", - strerror(errno)); + SCLogError(SC_ENOMEM, "SCMalloc failed: %s", strerror(errno)); exit(EXIT_FAILURE); } comp->pcap_buf_wrapper = SCFmemopen(comp->pcap_buf, @@ -1780,8 +1777,8 @@ static int PcapLogOpenFileCtx(PcapLogData *pl) (void)SCMkDir(dirfull, 0700); if ((pf->dirname = SCStrdup(dirfull)) == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for " - "directory name"); + SCLogError(SC_ENOMEM, "Error allocating memory for " + "directory name"); goto error; } @@ -1880,7 +1877,7 @@ static int PcapLogOpenFileCtx(PcapLogData *pl) } if ((pf->filename = SCStrdup(pl->filename)) == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory. For filename"); + SCLogError(SC_ENOMEM, "Error allocating memory. For filename"); goto error; } SCLogDebug("Opening pcap file log %s", pf->filename); diff --git a/src/log-tlsstore.c b/src/log-tlsstore.c index e743828e8a..b6a966dae5 100644 --- a/src/log-tlsstore.c +++ b/src/log-tlsstore.c @@ -117,7 +117,7 @@ static void LogTlsLogPem(LogTlsStoreLogThread *aft, const Packet *p, SSLState *s SCFree(aft->enc_buf); aft->enc_buf = NULL; aft->enc_buf_len = 0; - SCLogWarning(SC_ERR_MEM_ALLOC, "Can't allocate data for base64 encoding"); + SCLogWarning(SC_ENOMEM, "Can't allocate data for base64 encoding"); goto end_fp; } aft->enc_buf = ptmp; diff --git a/src/output-eve-syslog.c b/src/output-eve-syslog.c index 7dc0ca9085..f759440207 100644 --- a/src/output-eve-syslog.c +++ b/src/output-eve-syslog.c @@ -45,7 +45,7 @@ static int SyslogInit(ConfNode *conf, bool threaded, void **init_data) { Context *context = SCCalloc(1, sizeof(Context)); if (context == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate context for %s", OUTPUT_NAME); + SCLogError(SC_ENOMEM, "Unable to allocate context for %s", OUTPUT_NAME); return -1; } const char *facility_s = ConfNodeLookupChildValue(conf, "facility"); @@ -101,7 +101,7 @@ void SyslogInitialize(void) SCEveFileType *file_type = SCCalloc(1, sizeof(SCEveFileType)); if (file_type == NULL) { - FatalError(SC_ERR_MEM_ALLOC, "Unable to allocate memory for eve file type %s", OUTPUT_NAME); + FatalError(SC_ENOMEM, "Unable to allocate memory for eve file type %s", OUTPUT_NAME); } file_type->name = OUTPUT_NAME; diff --git a/src/output-lua.c b/src/output-lua.c index 67a0dcb951..f9ffb2d255 100644 --- a/src/output-lua.c +++ b/src/output-lua.c @@ -725,7 +725,7 @@ static OutputInitResult OutputLuaLogInit(ConfNode *conf) * on it's needs. */ OutputModule *om = SCCalloc(1, sizeof(*om)); if (om == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "calloc() failed"); + SCLogError(SC_ENOMEM, "calloc() failed"); goto error; } diff --git a/src/output.c b/src/output.c index a66c111756..914679aa26 100644 --- a/src/output.c +++ b/src/output.c @@ -833,8 +833,7 @@ void OutputRegisterFileRotationFlag(int *flag) { OutputFileRolloverFlag *flag_entry = SCCalloc(1, sizeof(*flag_entry)); if (unlikely(flag_entry == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate memory to register file rotation flag"); + SCLogError(SC_ENOMEM, "Failed to allocate memory to register file rotation flag"); return; } flag_entry->flag = flag; @@ -969,7 +968,7 @@ void OutputRegisterRootLogger(ThreadInitFunc ThreadInit, RootLogger *logger = SCCalloc(1, sizeof(*logger)); if (logger == NULL) { - FatalError(SC_ERR_MEM_ALLOC, "failed to alloc root logger"); + FatalError(SC_ENOMEM, "failed to alloc root logger"); } logger->ThreadInit = ThreadInit; logger->ThreadDeinit = ThreadDeinit; @@ -983,7 +982,7 @@ static void OutputRegisterActiveLogger(RootLogger *reg) { RootLogger *logger = SCCalloc(1, sizeof(*logger)); if (logger == NULL) { - FatalError(SC_ERR_MEM_ALLOC, "failed to alloc root logger"); + FatalError(SC_ENOMEM, "failed to alloc root logger"); } logger->ThreadInit = reg->ThreadInit; logger->ThreadDeinit = reg->ThreadDeinit; diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index 7442332ed1..2b01edab55 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -470,7 +470,7 @@ static void *ParseAFPConfig(const char *iface) RunModeEnablesBypassManager(); struct ebpf_timeout_config *ebt = SCCalloc(1, sizeof(struct ebpf_timeout_config)); if (ebt == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Flow bypass alloc error"); + SCLogError(SC_ENOMEM, "Flow bypass alloc error"); } else { memcpy(ebt, &(aconf->ebpf_t_config), sizeof(struct ebpf_timeout_config)); BypassedFlowManagerRegisterCheckFunc(NULL, diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index ef99c007a0..5118d2bd59 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -154,7 +154,7 @@ static char *AllocArgument(size_t arg_len) arg_len += 1; // null character ptr = (char *)SCCalloc(arg_len, sizeof(char)); if (ptr == NULL) - FatalError(SC_ERR_MEM_ALLOC, "Could not allocate memory for an argument"); + FatalError(SC_ENOMEM, "Could not allocate memory for an argument"); SCReturnPtr(ptr, "char *"); } @@ -201,7 +201,7 @@ static void ArgumentsInit(struct Arguments *args, unsigned capacity) SCEnter(); args->argv = SCCalloc(capacity, sizeof(ptrdiff_t)); // alloc array of pointers if (args->argv == NULL) - FatalError(SC_ERR_MEM_ALLOC, "Could not allocate memory for Arguments structure"); + FatalError(SC_ENOMEM, "Could not allocate memory for Arguments structure"); args->capacity = capacity; args->argc = 0; @@ -276,8 +276,7 @@ static void InitEal() // creating a shallow copy for cleanup because rte_eal_init changes array contents eal_argv = SCMalloc(args.argc * sizeof(args.argv)); if (eal_argv == NULL) { - FatalError( - SC_ERR_MEM_ALLOC, "Failed to allocate memory for the array of DPDK EAL arguments"); + FatalError(SC_ENOMEM, "Failed to allocate memory for the array of DPDK EAL arguments"); } memcpy(eal_argv, args.argv, args.argc * sizeof(*args.argv)); diff --git a/src/runmode-napatech.c b/src/runmode-napatech.c index 584e2d8e46..76726926d5 100644 --- a/src/runmode-napatech.c +++ b/src/runmode-napatech.c @@ -189,8 +189,7 @@ static void *NapatechConfigParser(const char *device) struct NapatechStreamDevConf *conf = SCCalloc(1, sizeof (struct NapatechStreamDevConf)); if (unlikely(conf == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate memory for NAPATECH device name."); + SCLogError(SC_ENOMEM, "Failed to allocate memory for NAPATECH device name."); return NULL; } diff --git a/src/runmode-pfring.c b/src/runmode-pfring.c index 95a837783a..58f3322a02 100644 --- a/src/runmode-pfring.c +++ b/src/runmode-pfring.c @@ -318,8 +318,7 @@ static void *ParsePfringConfig(const char *iface) if (strlen(bpf_filter) > 0) { pfconf->bpf_filter = SCStrdup(bpf_filter); if (unlikely(pfconf->bpf_filter == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, - "Can't allocate BPF filter string"); + SCLogError(SC_ENOMEM, "Can't allocate BPF filter string"); } else { SCLogDebug("Going to use command-line provided bpf filter %s", pfconf->bpf_filter); @@ -330,8 +329,7 @@ static void *ParsePfringConfig(const char *iface) if (strlen(bpf_filter) > 0) { pfconf->bpf_filter = SCStrdup(bpf_filter); if (unlikely(pfconf->bpf_filter == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, - "Can't allocate BPF filter string"); + SCLogError(SC_ENOMEM, "Can't allocate BPF filter string"); } else { SCLogDebug("Going to use bpf filter %s", pfconf->bpf_filter); diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index 9933cb3e66..3e3fe468b6 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -281,7 +281,7 @@ static TmEcode UnixListAddFile( return TM_ECODE_FAILED; cfile = SCMalloc(sizeof(PcapFiles)); if (unlikely(cfile == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate new file"); + SCLogError(SC_ENOMEM, "Unable to allocate new file"); return TM_ECODE_FAILED; } memset(cfile, 0, sizeof(PcapFiles)); @@ -289,7 +289,7 @@ static TmEcode UnixListAddFile( cfile->filename = SCStrdup(filename); if (unlikely(cfile->filename == NULL)) { SCFree(cfile); - SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup filename"); + SCLogError(SC_ENOMEM, "Unable to dup filename"); return TM_ECODE_FAILED; } @@ -298,7 +298,7 @@ static TmEcode UnixListAddFile( if (unlikely(cfile->output_dir == NULL)) { SCFree(cfile->filename); SCFree(cfile); - SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup output_dir"); + SCLogError(SC_ENOMEM, "Unable to dup output_dir"); return TM_ECODE_FAILED; } } @@ -1685,7 +1685,7 @@ static int RunModeUnixSocketMaster(void) PcapCommand *pcapcmd = SCMalloc(sizeof(PcapCommand)); if (unlikely(pcapcmd == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Can not allocate pcap command"); + SCLogError(SC_ENOMEM, "Can not allocate pcap command"); return 1; } TAILQ_INIT(&pcapcmd->files); diff --git a/src/runmodes.c b/src/runmodes.c index d602c25395..3d56d110af 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -490,11 +490,11 @@ void RunModeRegisterNewRunMode(enum RunModes runmode, mode->runmode = runmode; mode->name = SCStrdup(name); if (unlikely(mode->name == NULL)) { - FatalError(SC_ERR_MEM_ALLOC, "Failed to allocate string"); + FatalError(SC_ENOMEM, "Failed to allocate string"); } mode->description = SCStrdup(description); if (unlikely(mode->description == NULL)) { - FatalError(SC_ERR_MEM_ALLOC, "Failed to allocate string"); + FatalError(SC_ENOMEM, "Failed to allocate string"); } mode->RunModeFunc = RunModeFunc; diff --git a/src/source-af-packet.c b/src/source-af-packet.c index ebea917db5..901173e823 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -1689,11 +1689,8 @@ static int AFPSetupRing(AFPThreadVars *ptv, char *devname) r = setsockopt(ptv->socket, SOL_PACKET, PACKET_RX_RING, (void *) &ptv->req.v3, sizeof(ptv->req.v3)); if (r < 0) { - SCLogError(SC_ERR_MEM_ALLOC, - "Unable to allocate RX Ring for iface %s: (%d) %s", - devname, - errno, - strerror(errno)); + SCLogError(SC_ENOMEM, "Unable to allocate RX Ring for iface %s: (%d) %s", devname, + errno, strerror(errno)); return AFP_FATAL_ERROR; } } else { @@ -1712,20 +1709,15 @@ static int AFPSetupRing(AFPThreadVars *ptv, char *devname) SCLogInfo("Memory issue with ring parameters. Retrying."); continue; } - SCLogError(SC_ERR_MEM_ALLOC, - "Unable to allocate RX Ring for iface %s: (%d) %s", - devname, - errno, - strerror(errno)); + SCLogError(SC_EINVAL, "Unable to setup RX Ring for iface %s: (%d) %s", devname, + errno, strerror(errno)); return AFP_FATAL_ERROR; } else { break; } } if (order < 0) { - SCLogError(SC_ERR_MEM_ALLOC, - "Unable to allocate RX Ring for iface %s (order 0 failed)", - devname); + SCLogError(SC_EINVAL, "Unable to setup RX Ring for iface %s (order 0 failed)", devname); return AFP_FATAL_ERROR; } #ifdef HAVE_TPACKET_V3 @@ -1748,15 +1740,14 @@ static int AFPSetupRing(AFPThreadVars *ptv, char *devname) ptv->ring_buf = mmap(0, ptv->ring_buflen, PROT_READ|PROT_WRITE, mmap_flag, ptv->socket, 0); if (ptv->ring_buf == MAP_FAILED) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to mmap, error %s", - strerror(errno)); + SCLogError(SC_ENOMEM, "Unable to mmap, error %s", strerror(errno)); goto mmap_err; } #ifdef HAVE_TPACKET_V3 if (ptv->flags & AFP_TPACKET_V3) { ptv->ring.v3 = SCMalloc(ptv->req.v3.tp_block_nr * sizeof(*ptv->ring.v3)); if (!ptv->ring.v3) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to malloc ptv ring.v3"); + SCLogError(SC_ENOMEM, "Unable to malloc ptv ring.v3"); goto postmmap_err; } for (i = 0; i < ptv->req.v3.tp_block_nr; ++i) { @@ -1768,7 +1759,7 @@ static int AFPSetupRing(AFPThreadVars *ptv, char *devname) /* allocate a ring for each frame header pointer*/ ptv->ring.v2 = SCCalloc(ptv->req.v2.tp_frame_nr, sizeof(union thdr *)); if (ptv->ring.v2 == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate frame buf"); + SCLogError(SC_ENOMEM, "Unable to allocate frame buf"); goto postmmap_err; } /* fill the header ring with proper frame ptr*/ diff --git a/src/source-dpdk.c b/src/source-dpdk.c index 77342ab44d..543047e7a9 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -429,7 +429,7 @@ static TmEcode ReceiveDPDKThreadInit(ThreadVars *tv, const void *initdata, void ptv = SCCalloc(1, sizeof(DPDKThreadVars)); if (unlikely(ptv == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate memory"); + SCLogError(SC_ENOMEM, "Unable to allocate memory"); goto fail; } diff --git a/src/source-erf-dag.c b/src/source-erf-dag.c index 3f6365a850..424ecb3cee 100644 --- a/src/source-erf-dag.c +++ b/src/source-erf-dag.c @@ -510,9 +510,8 @@ ProcessErfDagRecord(ErfDagThreadVars *ewtn, char *prec) p = PacketGetFromQueueOrAlloc(); if (p == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate a Packet on stream: %d, DAG: %s", - ewtn->dagstream, ewtn->dagname); + SCLogError(SC_ENOMEM, "Failed to allocate a Packet on stream: %d, DAG: %s", ewtn->dagstream, + ewtn->dagname); SCReturnInt(TM_ECODE_FAILED); } PKT_SET_SRC(p, PKT_SRC_WIRE); diff --git a/src/source-erf-file.c b/src/source-erf-file.c index eaa750dbc8..e1b75b0120 100644 --- a/src/source-erf-file.c +++ b/src/source-erf-file.c @@ -131,7 +131,7 @@ TmEcode ReceiveErfFileLoop(ThreadVars *tv, void *data, void *slot) p = PacketGetFromQueueOrAlloc(); if (unlikely(p == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate a packet."); + SCLogError(SC_ENOMEM, "Failed to allocate a packet."); EngineStop(); SCReturnInt(TM_ECODE_FAILED); } @@ -235,7 +235,7 @@ ReceiveErfFileThreadInit(ThreadVars *tv, const void *initdata, void **data) ErfFileThreadVars *etv = SCMalloc(sizeof(ErfFileThreadVars)); if (unlikely(etv == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for ERF file thread vars."); + SCLogError(SC_ENOMEM, "Failed to allocate memory for ERF file thread vars."); fclose(erf); SCReturnInt(TM_ECODE_FAILED); } diff --git a/src/source-netmap.c b/src/source-netmap.c index 7c233fb2c9..61de69fe36 100644 --- a/src/source-netmap.c +++ b/src/source-netmap.c @@ -318,7 +318,7 @@ static int NetmapOpen(NetmapIfaceSettings *ns, NetmapDevice **pdevice, int verbo NetmapDevice *pdev = NULL, *spdev = NULL; pdev = SCCalloc(1, sizeof(*pdev)); if (unlikely(pdev == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Memory allocation failed"); + SCLogError(SC_ENOMEM, "Memory allocation failed"); goto error; } SC_ATOMIC_INIT(pdev->threads_run); @@ -512,7 +512,7 @@ static TmEcode ReceiveNetmapThreadInit(ThreadVars *tv, const void *initdata, voi NetmapThreadVars *ntv = SCCalloc(1, sizeof(*ntv)); if (unlikely(ntv == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Memory allocation failed"); + SCLogError(SC_ENOMEM, "Memory allocation failed"); goto error; } diff --git a/src/source-nfq.c b/src/source-nfq.c index d1a916f976..fcf28cb44a 100644 --- a/src/source-nfq.c +++ b/src/source-nfq.c @@ -891,7 +891,7 @@ int NFQParseAndRegisterQueues(const char *queues) // We do realloc() to preserve previously registered queues void *ptmp = SCRealloc(g_nfq_t, (receive_queue_num + num_queues) * sizeof(NFQThreadVars)); if (ptmp == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate NFQThreadVars"); + SCLogError(SC_ENOMEM, "Unable to allocate NFQThreadVars"); NFQContextsClean(); exit(EXIT_FAILURE); } @@ -900,7 +900,7 @@ int NFQParseAndRegisterQueues(const char *queues) ptmp = SCRealloc(g_nfq_q, (receive_queue_num + num_queues) * sizeof(NFQQueueVars)); if (ptmp == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate NFQQueueVars"); + SCLogError(SC_ENOMEM, "Unable to allocate NFQQueueVars"); NFQContextsClean(); exit(EXIT_FAILURE); } diff --git a/src/source-pcap-file-directory-helper.c b/src/source-pcap-file-directory-helper.c index 43ccadf697..d409810b28 100644 --- a/src/source-pcap-file-directory-helper.c +++ b/src/source-pcap-file-directory-helper.c @@ -367,14 +367,14 @@ TmEcode PcapDirectoryPopulateBuffer(PcapFileDirectoryVars *pv, file_to_add = SCCalloc(1, sizeof(PendingFile)); if (unlikely(file_to_add == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate pending file"); + SCLogError(SC_ENOMEM, "Failed to allocate pending file"); SCReturnInt(TM_ECODE_FAILED); } file_to_add->filename = SCStrdup(pathbuff); if (unlikely(file_to_add->filename == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to copy filename"); + SCLogError(SC_ENOMEM, "Failed to copy filename"); CleanupPendingFile(file_to_add); SCReturnInt(TM_ECODE_FAILED); @@ -434,14 +434,14 @@ TmEcode PcapDirectoryDispatchForTimeRange(PcapFileDirectoryVars *pv, PcapFileFileVars *pftv = SCMalloc(sizeof(PcapFileFileVars)); if (unlikely(pftv == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate PcapFileFileVars"); + SCLogError(SC_ENOMEM, "Failed to allocate PcapFileFileVars"); SCReturnInt(TM_ECODE_FAILED); } memset(pftv, 0, sizeof(PcapFileFileVars)); pftv->filename = SCStrdup(current_file->filename); if (unlikely(pftv->filename == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate filename"); + SCLogError(SC_ENOMEM, "Failed to allocate filename"); CleanupPcapFileFileVars(pftv); SCReturnInt(TM_ECODE_FAILED); } diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index 97f424943e..67987102e2 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -227,7 +227,7 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, const void *initdata, void **d } else { ptv->shared.bpf_string = SCStrdup(tmp_bpf_string); if (unlikely(ptv->shared.bpf_string == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate bpf_string"); + SCLogError(SC_ENOMEM, "Failed to allocate bpf_string"); CleanupPcapFileThreadVars(ptv); @@ -252,7 +252,7 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, const void *initdata, void **d SCLogDebug("argument %s was a file", (char *)initdata); PcapFileFileVars *pv = SCMalloc(sizeof(PcapFileFileVars)); if (unlikely(pv == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate file vars"); + SCLogError(SC_ENOMEM, "Failed to allocate file vars"); CleanupPcapFileThreadVars(ptv); SCReturnInt(TM_ECODE_OK); } @@ -260,7 +260,7 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, const void *initdata, void **d pv->filename = SCStrdup((char *)initdata); if (unlikely(pv->filename == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate filename"); + SCLogError(SC_ENOMEM, "Failed to allocate filename"); CleanupPcapFileFileVars(pv); CleanupPcapFileThreadVars(ptv); SCReturnInt(TM_ECODE_OK); @@ -282,7 +282,7 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, const void *initdata, void **d SCLogInfo("Argument %s was a directory", (char *)initdata); PcapFileDirectoryVars *pv = SCMalloc(sizeof(PcapFileDirectoryVars)); if (unlikely(pv == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate directory vars"); + SCLogError(SC_ENOMEM, "Failed to allocate directory vars"); closedir(directory); CleanupPcapFileThreadVars(ptv); SCReturnInt(TM_ECODE_OK); @@ -291,7 +291,7 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, const void *initdata, void **d pv->filename = SCStrdup((char*)initdata); if (unlikely(pv->filename == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate filename"); + SCLogError(SC_ENOMEM, "Failed to allocate filename"); CleanupPcapFileDirectoryVars(pv); CleanupPcapFileThreadVars(ptv); SCReturnInt(TM_ECODE_OK); diff --git a/src/source-pfring.c b/src/source-pfring.c index bb30df619e..4b8205f56c 100644 --- a/src/source-pfring.c +++ b/src/source-pfring.c @@ -507,7 +507,7 @@ TmEcode ReceivePfringThreadInit(ThreadVars *tv, const void *initdata, void **dat ptv->interface = SCStrdup(pfconf->iface); if (unlikely(ptv->interface == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate device string"); + SCLogError(SC_ENOMEM, "Unable to allocate device string"); SCFree(ptv); SCReturnInt(TM_ECODE_FAILED); } @@ -603,7 +603,7 @@ TmEcode ReceivePfringThreadInit(ThreadVars *tv, const void *initdata, void **dat if (pfconf->bpf_filter) { ptv->bpf_filter = SCStrdup(pfconf->bpf_filter); if (unlikely(ptv->bpf_filter == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Set PF_RING bpf filter failed."); + SCLogError(SC_ENOMEM, "Set PF_RING bpf filter failed."); } else { SCMutexLock(&pfring_bpf_set_filter_lock); rc = pfring_set_bpf_filter(ptv->pd, ptv->bpf_filter); diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index 4d0a36a68d..4dc2cbd76a 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -270,8 +270,8 @@ static void *TcpSegmentPoolAlloc(void) seg->pcap_hdr_storage = SCCalloc(1, sizeof(TcpSegmentPcapHdrStorage)); if (seg->pcap_hdr_storage == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate memory for " - "TcpSegmentPcapHdrStorage"); + SCLogError(SC_ENOMEM, "Unable to allocate memory for " + "TcpSegmentPcapHdrStorage"); SCFree(seg); return NULL; } else { @@ -279,9 +279,9 @@ static void *TcpSegmentPoolAlloc(void) seg->pcap_hdr_storage->pkt_hdr = SCCalloc(1, sizeof(uint8_t) * TCPSEG_PKT_HDR_DEFAULT_SIZE); if (seg->pcap_hdr_storage->pkt_hdr == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate memory for " - "packet header data within " - "TcpSegmentPcapHdrStorage"); + SCLogError(SC_ENOMEM, "Unable to allocate memory for " + "packet header data within " + "TcpSegmentPcapHdrStorage"); SCFree(seg->pcap_hdr_storage); SCFree(seg); return NULL; diff --git a/src/suricata.c b/src/suricata.c index f85402c37d..ab8b542e32 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -525,7 +525,7 @@ static void SetBpfStringFromFile(char *filename) bpf_filter = SCMalloc(bpf_len); if (unlikely(bpf_filter == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate buffer for bpf filter in file %s", filename); + SCLogError(SC_ENOMEM, "Failed to allocate buffer for bpf filter in file %s", filename); exit(EXIT_FAILURE); } memset(bpf_filter, 0x00, bpf_len); @@ -1575,8 +1575,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri) else if(strcmp((long_opts[option_index]).name, "pidfile") == 0) { suri->pid_filename = SCStrdup(optarg); if (suri->pid_filename == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "strdup failed: %s", - strerror(errno)); + SCLogError(SC_ENOMEM, "strdup failed: %s", strerror(errno)); return TM_ECODE_FAILED; } } @@ -1764,7 +1763,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri) suri->strict_rule_parsing_string = SCStrdup(optarg); } if (suri->strict_rule_parsing_string == NULL) { - FatalError(SC_ERR_MEM_ALLOC, "failed to duplicate 'strict' string"); + FatalError(SC_ENOMEM, "failed to duplicate 'strict' string"); } } else { int r = ExceptionSimulationCommandlineParser( @@ -2074,7 +2073,7 @@ static int MayDaemonize(SCInstance *suri) /* The pid file name may be in config memory, but is needed later. */ suri->pid_filename = SCStrdup(pid_filename); if (suri->pid_filename == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "strdup failed: %s", strerror(errno)); + SCLogError(SC_ENOMEM, "strdup failed: %s", strerror(errno)); return TM_ECODE_FAILED; } } diff --git a/src/tm-queues.c b/src/tm-queues.c index 6c745bc275..248cd71d90 100644 --- a/src/tm-queues.c +++ b/src/tm-queues.c @@ -36,18 +36,18 @@ Tmq *TmqCreateQueue(const char *name) { Tmq *q = SCCalloc(1, sizeof(*q)); if (q == NULL) - FatalError(SC_ERR_MEM_ALLOC, "SCCalloc failed"); + FatalError(SC_ENOMEM, "SCCalloc failed"); q->name = SCStrdup(name); if (q->name == NULL) - FatalError(SC_ERR_MEM_ALLOC, "SCStrdup failed"); + FatalError(SC_ENOMEM, "SCStrdup failed"); q->id = tmq_id++; q->is_packet_pool = (strcmp(q->name, "packetpool") == 0); if (!q->is_packet_pool) { q->pq = PacketQueueAlloc(); if (q->pq == NULL) - FatalError(SC_ERR_MEM_ALLOC, "PacketQueueAlloc failed"); + FatalError(SC_ENOMEM, "PacketQueueAlloc failed"); } TAILQ_INSERT_HEAD(&tmq_list, q, next); diff --git a/src/tm-threads.c b/src/tm-threads.c index b7b2be628e..1bea0fd00b 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -282,7 +282,7 @@ static void *TmThreadsSlotPktAcqLoop(void *td) } else if (slot->tm_id == TMM_FLOWWORKER) { tv->stream_pq_local = SCCalloc(1, sizeof(PacketQueue)); if (tv->stream_pq_local == NULL) - FatalError(SC_ERR_MEM_ALLOC, "failed to alloc PacketQueue"); + FatalError(SC_ENOMEM, "failed to alloc PacketQueue"); SCMutexInit(&tv->stream_pq_local->mutex_q, NULL); tv->stream_pq = tv->stream_pq_local; tv->tm_flowworker = slot; @@ -412,7 +412,7 @@ static void *TmThreadsSlotVar(void *td) } else if (s->tm_id == TMM_FLOWWORKER) { tv->stream_pq_local = SCCalloc(1, sizeof(PacketQueue)); if (tv->stream_pq_local == NULL) - FatalError(SC_ERR_MEM_ALLOC, "failed to alloc PacketQueue"); + FatalError(SC_ENOMEM, "failed to alloc PacketQueue"); SCMutexInit(&tv->stream_pq_local->mutex_q, NULL); tv->stream_pq = tv->stream_pq_local; tv->tm_flowworker = s; diff --git a/src/unix-manager.c b/src/unix-manager.c index a6fde27c96..313de0f968 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -236,12 +236,12 @@ static UnixClient *UnixClientAlloc(void) { UnixClient *uclient = SCMalloc(sizeof(UnixClient)); if (unlikely(uclient == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate new client"); + SCLogError(SC_ENOMEM, "Can't allocate new client"); return NULL; } uclient->mbuf = MemBufferCreateNew(CLIENT_BUFFER_SIZE); if (uclient->mbuf == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate new client send buffer"); + SCLogError(sc_errno, "Can't allocate new client send buffer"); SCFree(uclient); return NULL; } @@ -985,12 +985,12 @@ TmEcode UnixManagerRegisterCommand(const char * keyword, cmd = SCMalloc(sizeof(Command)); if (unlikely(cmd == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't alloc cmd"); + SCLogError(SC_ENOMEM, "Can't alloc cmd"); SCReturnInt(TM_ECODE_FAILED); } cmd->name = SCStrdup(keyword); if (unlikely(cmd->name == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't alloc cmd name"); + SCLogError(SC_ENOMEM, "Can't alloc cmd name"); SCFree(cmd); SCReturnInt(TM_ECODE_FAILED); } @@ -1026,7 +1026,7 @@ TmEcode UnixManagerRegisterBackgroundTask(TmEcode (*Func)(void *), task = SCMalloc(sizeof(Task)); if (unlikely(task == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't alloc task"); + SCLogError(SC_ENOMEM, "Can't alloc task"); SCReturnInt(TM_ECODE_FAILED); } task->Func = Func; diff --git a/src/util-classification-config.c b/src/util-classification-config.c index 669338e1a6..4a81be55f5 100644 --- a/src/util-classification-config.c +++ b/src/util-classification-config.c @@ -213,7 +213,7 @@ static char *SCClassConfStringToLowercase(const char *str) char *temp_str = NULL; if ( (new_str = SCStrdup(str)) == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + SCLogError(SC_ENOMEM, "Error allocating memory"); return NULL; } @@ -404,7 +404,7 @@ static SCClassConfClasstype *SCClassConfAllocClasstype(uint16_t classtype_id, if (classtype_desc != NULL && (ct->classtype_desc = SCStrdup(classtype_desc)) == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + SCLogError(SC_ENOMEM, "Error allocating memory"); SCClassConfDeAllocClasstype(ct); return NULL; diff --git a/src/util-detect.c b/src/util-detect.c index 37ed2e3c40..59c5d656fa 100644 --- a/src/util-detect.c +++ b/src/util-detect.c @@ -65,13 +65,13 @@ static int SigStringAddSig(SigString *sig, const char *sig_file, sig->filename = SCStrdup(sig_file); if (sig->filename == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + SCLogError(SC_ENOMEM, "Error allocating memory"); return 0; } sig->sig_str = SCStrdup(sig_str); if (sig->sig_str == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + SCLogError(SC_ENOMEM, "Error allocating memory"); SCFree(sig->filename); return 0; } @@ -79,7 +79,7 @@ static int SigStringAddSig(SigString *sig, const char *sig_file, if (sig_error) { sig->sig_error = SCStrdup(sig_error); if (sig->sig_error == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + SCLogError(SC_ENOMEM, "Error allocating memory"); SCFree(sig->filename); SCFree(sig->sig_str); return 0; diff --git a/src/util-device.c b/src/util-device.c index 26220ecfb3..1143286381 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -509,7 +509,7 @@ int LiveDevUseBypass(LiveDevice *dev) { BypassInfo *bpinfo = SCCalloc(1, sizeof(*bpinfo)); if (bpinfo == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate bypass info structure"); + SCLogError(SC_ENOMEM, "Can't allocate bypass info structure"); return -1; } diff --git a/src/util-ebpf.c b/src/util-ebpf.c index 2d7b0ad220..b4a0778528 100644 --- a/src/util-ebpf.c +++ b/src/util-ebpf.c @@ -218,7 +218,7 @@ static int EBPFLoadPinnedMaps(LiveDevice *livedev, struct ebpf_timeout_config *c struct bpf_maps_info *bpf_map_data = SCCalloc(1, sizeof(*bpf_map_data)); if (bpf_map_data == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate bpf map array"); + SCLogError(SC_ENOMEM, "Can't allocate bpf map array"); return -1; } @@ -288,7 +288,7 @@ alloc_error: SCFree(bpf_map_data->array[i].name); } bpf_map_data->last = 0; - SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate bpf map name"); + SCLogError(SC_ENOMEM, "Can't allocate bpf map name"); return -1; } @@ -336,8 +336,7 @@ int EBPFLoadFile(const char *iface, const char *path, const char * section, * locked memory so we set it to unlimited to avoid a ENOPERM error */ struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; if (setrlimit(RLIMIT_MEMLOCK, &r) != 0) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to lock memory: %s (%d)", - strerror(errno), errno); + SCLogError(SC_ENOMEM, "Unable to lock memory: %s (%d)", strerror(errno), errno); return -1; } @@ -422,7 +421,7 @@ int EBPFLoadFile(const char *iface, const char *path, const char * section, * that we use bpf_maps_info:: */ struct bpf_maps_info *bpf_map_data = SCCalloc(1, sizeof(*bpf_map_data)); if (bpf_map_data == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate bpf map array"); + SCLogError(SC_ENOMEM, "Can't allocate bpf map array"); return -1; } @@ -438,7 +437,7 @@ int EBPFLoadFile(const char *iface, const char *path, const char * section, snprintf(bpf_map_data->array[bpf_map_data->last].iface, IFNAMSIZ, "%s", iface); if (!bpf_map_data->array[bpf_map_data->last].name) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to duplicate map name"); + SCLogError(SC_ENOMEM, "Unable to duplicate map name"); BpfMapsInfoFree(bpf_map_data); return -1; } diff --git a/src/util-file.c b/src/util-file.c index ba8ea39469..3ffba673f3 100644 --- a/src/util-file.c +++ b/src/util-file.c @@ -491,7 +491,7 @@ FileContainer *FileContainerAlloc(void) { FileContainer *new = SCMalloc(sizeof(FileContainer)); if (unlikely(new == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating mem"); + SCLogError(SC_ENOMEM, "Error allocating mem"); return NULL; } memset(new, 0, sizeof(FileContainer)); @@ -552,7 +552,7 @@ static File *FileAlloc(const uint8_t *name, uint16_t name_len) { File *new = SCMalloc(sizeof(File)); if (unlikely(new == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating mem"); + SCLogError(SC_ENOMEM, "Error allocating mem"); return NULL; } memset(new, 0, sizeof(File)); diff --git a/src/util-ja3.c b/src/util-ja3.c index 78a49a61bd..dbbf28063f 100644 --- a/src/util-ja3.c +++ b/src/util-ja3.c @@ -83,7 +83,7 @@ static int Ja3BufferResizeIfFull(JA3Buffer *buffer, uint32_t len) buffer->size *= 2; char *tmp = SCRealloc(buffer->data, buffer->size); if (tmp == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error resizing JA3 buffer"); + SCLogError(SC_ENOMEM, "Error resizing JA3 buffer"); return -1; } buffer->data = tmp; @@ -177,8 +177,7 @@ int Ja3BufferAddValue(JA3Buffer **buffer, uint32_t value) if ((*buffer)->data == NULL) { (*buffer)->data = SCMalloc(JA3_BUFFER_INITIAL_SIZE); if ((*buffer)->data == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, - "Error allocating memory for JA3 data"); + SCLogError(SC_ENOMEM, "Error allocating memory for JA3 data"); Ja3BufferFree(buffer); return -1; } @@ -226,8 +225,7 @@ char *Ja3GenerateHash(JA3Buffer *buffer) char *ja3_hash = SCMalloc(SC_MD5_HEX_LEN + 1); if (ja3_hash == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, - "Error allocating memory for JA3 hash"); + SCLogError(SC_ENOMEM, "Error allocating memory for JA3 hash"); return NULL; } diff --git a/src/util-landlock.c b/src/util-landlock.c index fa15a08e04..4c6c3dba47 100644 --- a/src/util-landlock.c +++ b/src/util-landlock.c @@ -90,7 +90,7 @@ static inline struct landlock_ruleset *LandlockCreateRuleset(void) { struct landlock_ruleset *ruleset = SCCalloc(1, sizeof(struct landlock_ruleset)); if (ruleset == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Can't alloc landlock ruleset"); + SCLogError(SC_ENOMEM, "Can't alloc landlock ruleset"); return NULL; } diff --git a/src/util-log-redis.c b/src/util-log-redis.c index bfaf29a5a9..cec126505a 100644 --- a/src/util-log-redis.c +++ b/src/util-log-redis.c @@ -215,7 +215,7 @@ static int SCConfLogReopenAsyncRedis(LogFileCtx *log_ctx) } if (ctx->async == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocate redis async."); + SCLogError(SC_ENOMEM, "Error allocate redis async."); ctx->tried = time(NULL); return -1; } diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index 0b8f9b4e6e..b9731ad351 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -331,20 +331,20 @@ bool SCLogOpenThreadedFile( { parent_ctx->threads = SCCalloc(1, sizeof(LogThreadedFileCtx)); if (!parent_ctx->threads) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate threads container"); + SCLogError(SC_ENOMEM, "Unable to allocate threads container"); return false; } parent_ctx->threads->append = SCStrdup(append == NULL ? DEFAULT_LOG_MODE_APPEND : append); if (!parent_ctx->threads->append) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate threads append setting"); + SCLogError(SC_ENOMEM, "Unable to allocate threads append setting"); goto error_exit; } parent_ctx->threads->slot_count = slot_count; parent_ctx->threads->lf_slots = SCCalloc(slot_count, sizeof(LogFileCtx *)); if (!parent_ctx->threads->lf_slots) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate thread slots"); + SCLogError(SC_ENOMEM, "Unable to allocate thread slots"); goto error_exit; } SCLogDebug("Allocated %d file context pointers for threaded array", @@ -586,8 +586,7 @@ SCConfLogOpenGeneric(ConfNode *conf, } log_ctx->filename = SCStrdup(log_path); if (unlikely(log_ctx->filename == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, - "Failed to allocate memory for filename"); + SCLogError(SC_ENOMEM, "Failed to allocate memory for filename"); return -1; } @@ -696,7 +695,7 @@ LogFileCtx *LogFileEnsureExists(LogFileCtx *parent_ctx, int thread_id) if (new_array == NULL) { SCMutexUnlock(&parent_ctx->threads->mutex); - SCLogError(SC_ERR_MEM_ALLOC, "Unable to increase file context array size to %d", new_size); + SCLogError(SC_ENOMEM, "Unable to increase file context array size to %d", new_size); return NULL; } @@ -775,7 +774,7 @@ static bool LogFileNewThreadedCtx(LogFileCtx *parent_ctx, const char *log_path, { LogFileCtx *thread = SCCalloc(1, sizeof(LogFileCtx)); if (!thread) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate thread file context slot %d", thread_id); + SCLogError(SC_ENOMEM, "Unable to allocate thread file context slot %d", thread_id); return false; } @@ -793,8 +792,7 @@ static bool LogFileNewThreadedCtx(LogFileCtx *parent_ctx, const char *log_path, } thread->filename = SCStrdup(fname); if (!thread->filename) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to duplicate filename for context slot %d", - thread_id); + SCLogError(SC_ENOMEM, "Unable to duplicate filename for context slot %d", thread_id); goto error; } thread->is_regular = true; diff --git a/src/util-macset.c b/src/util-macset.c index 0896e907cd..efa74ce0f0 100644 --- a/src/util-macset.c +++ b/src/util-macset.c @@ -95,7 +95,7 @@ MacSet *MacSetInit(int size) } ms = SCCalloc(1, sizeof(*ms)); if (unlikely(ms == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate MacSet memory"); + SCLogError(SC_ENOMEM, "Unable to allocate MacSet memory"); return NULL; } (void) SC_ATOMIC_ADD(flow_memuse, (sizeof(*ms))); @@ -133,8 +133,8 @@ static inline void MacUpdateEntry(MacSet *ms, uint8_t *addr, int side, ThreadVar } ms->buf[side] = SCCalloc(ms->size, sizeof(MacAddr)); if (unlikely(ms->buf[side] == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate " - "MacSet memory"); + SCLogError(SC_ENOMEM, "Unable to allocate " + "MacSet memory"); return; } (void) SC_ATOMIC_ADD(flow_memuse, (ms->size * sizeof(MacAddr))); diff --git a/src/util-magic.c b/src/util-magic.c index 941c98f56c..e742d18def 100644 --- a/src/util-magic.c +++ b/src/util-magic.c @@ -113,7 +113,7 @@ char *MagicThreadLookup(magic_t *ctx, const uint8_t *buf, uint32_t buflen) if (result != NULL) { magic = SCStrdup(result); if (unlikely(magic == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup magic"); + SCLogError(SC_ENOMEM, "Unable to dup magic"); } } } diff --git a/src/util-mem.c b/src/util-mem.c index 551d05b78e..2f612fabd7 100644 --- a/src/util-mem.c +++ b/src/util-mem.c @@ -32,8 +32,10 @@ void *SCMallocFunc(const size_t sz) if (unlikely(ptrmem == NULL)) { if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) { uintmax_t scmalloc_size_ = (uintmax_t)sz; - SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s, while trying " - "to allocate %"PRIuMAX" bytes", strerror(errno), scmalloc_size_); + SCLogError(SC_ENOMEM, + "SCMalloc failed: %s, while trying " + "to allocate %" PRIuMAX " bytes", + strerror(errno), scmalloc_size_); FatalError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); } } @@ -45,8 +47,10 @@ void *SCReallocFunc(void *ptr, const size_t size) void *ptrmem = realloc(ptr, size); if (unlikely(ptrmem == NULL)) { if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) { - SCLogError(SC_ERR_MEM_ALLOC, "SCRealloc failed: %s, while trying " - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)size); + SCLogError(SC_ENOMEM, + "SCRealloc failed: %s, while trying " + "to allocate %" PRIuMAX " bytes", + strerror(errno), (uintmax_t)size); FatalError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); } } @@ -58,8 +62,10 @@ void *SCCallocFunc(const size_t nm, const size_t sz) void *ptrmem = calloc(nm, sz); if (unlikely(ptrmem == NULL)) { if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) { - SCLogError(SC_ERR_MEM_ALLOC, "SCCalloc failed: %s, while trying " - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)nm*sz); + SCLogError(SC_ENOMEM, + "SCCalloc failed: %s, while trying " + "to allocate %" PRIuMAX " bytes", + strerror(errno), (uintmax_t)nm * sz); FatalError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); } } @@ -72,8 +78,10 @@ char *SCStrdupFunc(const char *s) if (unlikely(ptrmem == NULL)) { if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) { size_t _scstrdup_len = strlen(s); - SCLogError(SC_ERR_MEM_ALLOC, "SCStrdup failed: %s, while trying " - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)_scstrdup_len); + SCLogError(SC_ENOMEM, + "SCStrdup failed: %s, while trying " + "to allocate %" PRIuMAX " bytes", + strerror(errno), (uintmax_t)_scstrdup_len); FatalError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); } } @@ -93,8 +101,10 @@ char *SCStrndupFunc(const char *s, size_t n) #endif if (unlikely(ptrmem == NULL)) { if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) { - SCLogError(SC_ERR_MEM_ALLOC, "SCStrndup failed: %s, while trying " - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(n + 1)); + SCLogError(SC_ENOMEM, + "SCStrndup failed: %s, while trying " + "to allocate %" PRIuMAX " bytes", + strerror(errno), (uintmax_t)(n + 1)); FatalError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); } } @@ -107,8 +117,10 @@ void *SCMallocAlignedFunc(const size_t size, const size_t align) void *ptrmem = _mm_malloc(size, align); if (unlikely(ptrmem == NULL)) { if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) { - SCLogError(SC_ERR_MEM_ALLOC, "SCMallocAligned(posix_memalign) failed: %s, while trying " - "to allocate %"PRIuMAX" bytes, alignment %"PRIuMAX, strerror(errno), (uintmax_t)size, (uintmax_t)align); + SCLogError(SC_ENOMEM, + "SCMallocAligned(posix_memalign) failed: %s, while trying " + "to allocate %" PRIuMAX " bytes, alignment %" PRIuMAX, + strerror(errno), (uintmax_t)size, (uintmax_t)align); FatalError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); } } @@ -121,8 +133,10 @@ void *SCMallocAlignedFunc(const size_t size, const size_t align) ptrmem = NULL; } if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) { - SCLogError(SC_ERR_MEM_ALLOC, "SCMallocAligned(posix_memalign) failed: %s, while trying " - "to allocate %"PRIuMAX" bytes, alignment %"PRIuMAX, strerror(errno), (uintmax_t)size, (uintmax_t)align); + SCLogError(SC_ENOMEM, + "SCMallocAligned(posix_memalign) failed: %s, while trying " + "to allocate %" PRIuMAX " bytes, alignment %" PRIuMAX, + strerror(errno), (uintmax_t)size, (uintmax_t)align); FatalError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); } } diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 36d368b298..5a13d3ae6f 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -127,9 +127,10 @@ static inline size_t SCACCheckSafeSizetMult(size_t a, size_t b) { /* check for safety of multiplication operation */ if (b > 0 && a > SIZE_MAX / b) { - SCLogError(SC_ERR_MEM_ALLOC, "%"PRIuMAX" * %"PRIuMAX" > %" - PRIuMAX" would overflow size_t calculating buffer size", - (uintmax_t) a, (uintmax_t) b, (uintmax_t) SIZE_MAX); + SCLogError(SC_EINVAL, + "%" PRIuMAX " * %" PRIuMAX " > %" PRIuMAX + " would overflow size_t calculating buffer size", + (uintmax_t)a, (uintmax_t)b, (uintmax_t)SIZE_MAX); exit(EXIT_FAILURE); } return a * b; diff --git a/src/util-plugin.c b/src/util-plugin.c index b0e9d62866..f2e5e4a1cf 100644 --- a/src/util-plugin.c +++ b/src/util-plugin.c @@ -54,7 +54,7 @@ bool RegisterPlugin(SCPlugin *plugin, void *lib) PluginListNode *node = SCCalloc(1, sizeof(*node)); if (node == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for plugin"); + SCLogError(SC_ENOMEM, "Failed to allocate memory for plugin"); return false; } node->plugin = plugin; diff --git a/src/util-prefilter.c b/src/util-prefilter.c index ca59a1b48e..dd81be1cf3 100644 --- a/src/util-prefilter.c +++ b/src/util-prefilter.c @@ -83,8 +83,8 @@ PrefilterAddSidsResize(PrefilterRuleStore *pmq, uint32_t new_size) new_size * sizeof(SigIntId)); if (unlikely(new_array == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Failed to realloc PatternMatchQueue" - " rule ID array. Some signature ID matches lost"); + SCLogError(SC_ENOMEM, "Failed to realloc PatternMatchQueue" + " rule ID array. Some signature ID matches lost"); return 0; } } diff --git a/src/util-profiling-rules.c b/src/util-profiling-rules.c index c221de6901..3b00d8d95e 100644 --- a/src/util-profiling-rules.c +++ b/src/util-profiling-rules.c @@ -436,7 +436,7 @@ SCProfilingRuleDump(SCProfileDetectCtx *rules_ctx) int summary_size = sizeof(SCProfileSummary) * rules_ctx->size; SCProfileSummary *summary = SCMalloc(summary_size); if (unlikely(summary == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for profiling summary"); + SCLogError(SC_ENOMEM, "Error allocating memory for profiling summary"); return; } diff --git a/src/util-proto-name.c b/src/util-proto-name.c index e74b01daf6..b7a54ea171 100644 --- a/src/util-proto-name.c +++ b/src/util-proto-name.c @@ -390,7 +390,7 @@ static void ProtoNameAddEntry(const char *proto_name, const uint8_t proto_number proto_ent->name = SCStrdup(proto_name); if (!proto_ent->name) - FatalError(SC_ERR_MEM_ALLOC, "Unable to allocate memory for protocol name entries"); + FatalError(SC_ENOMEM, "Unable to allocate memory for protocol name entries"); proto_ent->number = proto_number; diff --git a/src/util-radix-tree.c b/src/util-radix-tree.c index c98c2c72d6..0de3ef19fe 100644 --- a/src/util-radix-tree.c +++ b/src/util-radix-tree.c @@ -48,7 +48,7 @@ static SCRadixUserData *SCRadixAllocSCRadixUserData(uint8_t netmask, void *user) { SCRadixUserData *user_data = SCMalloc(sizeof(SCRadixUserData)); if (unlikely(user_data == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + SCLogError(SC_ENOMEM, "Error allocating memory"); return NULL; } @@ -547,7 +547,7 @@ static SCRadixNode *SCRadixAddKey( sizeof(uint8_t)))) == NULL) { SCFree(node->netmasks); node->netmasks = NULL; - SCLogError(SC_ERR_MEM_ALLOC, "Fatal error encountered in SCRadixAddKey. Mem not allocated"); + SCLogError(SC_ENOMEM, "Fatal error encountered in SCRadixAddKey. Mem not allocated"); return NULL; } node->netmasks = ptmp; @@ -751,7 +751,8 @@ static SCRadixNode *SCRadixAddKey( if (i < node->netmask_cnt) { if ( (inter_node->netmasks = SCMalloc((node->netmask_cnt - i) * sizeof(uint8_t))) == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Fatal error encountered in SCRadixAddKey. Mem not allocated..."); + SCLogError(SC_ENOMEM, + "Fatal error encountered in SCRadixAddKey. Mem not allocated..."); SCRadixReleaseNode(inter_node, tree); SCRadixReleaseNode(new_node, tree); return NULL; diff --git a/src/util-runmodes.c b/src/util-runmodes.c index 272a1f1d4f..3510a5ec43 100644 --- a/src/util-runmodes.c +++ b/src/util-runmodes.c @@ -64,8 +64,7 @@ char *RunmodeAutoFpCreatePickupQueuesString(int n) char *queues = SCMalloc(queues_size); if (unlikely(queues == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "failed to alloc queues buffer: %s", - strerror(errno)); + SCLogError(SC_ENOMEM, "failed to alloc queues buffer: %s", strerror(errno)); return NULL; } memset(queues, 0x00, queues_size); @@ -169,7 +168,8 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser, for (int thread = 0; thread < threads_count; thread++) { char *printable_threadname = SCMalloc(sizeof(char) * (strlen(thread_name)+5+strlen(dev))); if (unlikely(printable_threadname == NULL)) { - FatalError(SC_ERR_MEM_ALLOC, "failed to alloc printable thread name: %s", strerror(errno)); + FatalError(SC_ENOMEM, "failed to alloc printable thread name: %s", + strerror(errno)); } snprintf(tname, sizeof(tname), "%s#%02d-%s", thread_name, thread+1, visual_devname); @@ -271,7 +271,7 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod const char *visual_devname = LiveGetShortName(live_dev); char *printable_threadname = SCMalloc(sizeof(char) * (strlen(thread_name)+5+strlen(live_dev))); if (unlikely(printable_threadname == NULL)) { - FatalError(SC_ERR_MEM_ALLOC, "failed to alloc printable thread name: %s", strerror(errno)); + FatalError(SC_ENOMEM, "failed to alloc printable thread name: %s", strerror(errno)); exit(EXIT_FAILURE); } diff --git a/src/util-threshold-config.c b/src/util-threshold-config.c index 4d8e61aa40..dc9d3a9b79 100644 --- a/src/util-threshold-config.c +++ b/src/util-threshold-config.c @@ -352,7 +352,7 @@ static int SetupSuppressRule(DetectEngineCtx *de_ctx, uint32_t id, uint32_t gid, sm = SigMatchAlloc(); if (sm == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating SigMatch"); + SCLogError(SC_ENOMEM, "Error allocating SigMatch"); goto error; } @@ -381,7 +381,7 @@ static int SetupSuppressRule(DetectEngineCtx *de_ctx, uint32_t id, uint32_t gid, sm = SigMatchAlloc(); if (sm == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating SigMatch"); + SCLogError(SC_ENOMEM, "Error allocating SigMatch"); goto error; } @@ -412,7 +412,7 @@ static int SetupSuppressRule(DetectEngineCtx *de_ctx, uint32_t id, uint32_t gid, sm = SigMatchAlloc(); if (sm == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating SigMatch"); + SCLogError(SC_ENOMEM, "Error allocating SigMatch"); goto error; } @@ -494,7 +494,7 @@ static int SetupThresholdRule(DetectEngineCtx *de_ctx, uint32_t id, uint32_t gid sm = SigMatchAlloc(); if (sm == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating SigMatch"); + SCLogError(SC_ENOMEM, "Error allocating SigMatch"); goto error; } @@ -534,7 +534,7 @@ static int SetupThresholdRule(DetectEngineCtx *de_ctx, uint32_t id, uint32_t gid sm = SigMatchAlloc(); if (sm == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating SigMatch"); + SCLogError(SC_ENOMEM, "Error allocating SigMatch"); goto error; } @@ -605,7 +605,7 @@ static int SetupThresholdRule(DetectEngineCtx *de_ctx, uint32_t id, uint32_t gid sm = SigMatchAlloc(); if (sm == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating SigMatch"); + SCLogError(SC_ENOMEM, "Error allocating SigMatch"); goto error; }