error: use SC_ENOMEM for alloc errors

pull/8304/head
Victor Julien 3 years ago
parent d2c98c3281
commit e042cd785e

@ -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;

@ -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;
}

@ -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;
}

@ -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;

@ -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;

@ -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)",

@ -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;
}

@ -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;
}

@ -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);

@ -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;
}

@ -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;

@ -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;
}

@ -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;
}

@ -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);
}

@ -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?
}

@ -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);

@ -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;

@ -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);

@ -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;

@ -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;

@ -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;
}

@ -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;

@ -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,

@ -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));

@ -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;
}

@ -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);

@ -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);

@ -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;

@ -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*/

@ -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;
}

@ -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);

@ -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);
}

@ -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;
}

@ -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);
}

@ -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);
}

@ -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);

@ -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);

@ -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;

@ -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;
}
}

@ -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);

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;
}

@ -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;
}

@ -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));

@ -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;
}

@ -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;
}

@ -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;
}

@ -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;

@ -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)));

@ -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");
}
}
}

@ -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...");
}
}

@ -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;

@ -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;

@ -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;
}
}

@ -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;
}

@ -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;

@ -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;

@ -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);
}

@ -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;
}

Loading…
Cancel
Save