Fix inconsistent use of dynamic memory allocation

remotes/origin/master-1.0.x
Gerardo Iglesias Galvan 17 years ago committed by Victor Julien
parent c6bf08eec8
commit 9f4fae5b1a

@ -213,9 +213,8 @@ TmEcode AlertDebugLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
TmEcode AlertDebugLogThreadInit(ThreadVars *t, void *initdata, void **data)
{
AlertDebugLogThread *aft = SCMalloc(sizeof(AlertDebugLogThread));
if (aft == NULL) {
if (aft == NULL)
return TM_ECODE_FAILED;
}
memset(aft, 0, sizeof(AlertDebugLogThread));
if(initdata == NULL)
@ -281,11 +280,8 @@ OutputCtx *AlertDebugLogInitCtx(ConfNode *conf)
return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate OutputCtx for AlertDebugLog");
exit(EXIT_FAILURE);
}
if (output_ctx == NULL)
return NULL;
output_ctx->data = file_ctx;
return output_ctx;

@ -216,9 +216,8 @@ TmEcode AlertFastLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
TmEcode AlertFastLogThreadInit(ThreadVars *t, void *initdata, void **data)
{
AlertFastLogThread *aft = SCMalloc(sizeof(AlertFastLogThread));
if (aft == NULL) {
if (aft == NULL)
return TM_ECODE_FAILED;
}
memset(aft, 0, sizeof(AlertFastLogThread));
if(initdata == NULL)
{
@ -278,11 +277,8 @@ OutputCtx *AlertFastLogInitCtx(ConfNode *conf)
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocated memory for OutputCtx");
exit(EXIT_FAILURE);
}
if (output_ctx == NULL)
return NULL;
output_ctx->data = logfile_ctx;
output_ctx->DeInit = AlertFastLogDeInitCtx;

@ -731,9 +731,8 @@ TmEcode AlertPreludeThreadInit(ThreadVars *t, void *initdata, void **data)
}
aun = SCMalloc(sizeof(AlertPreludeThread));
if (aun == NULL) {
if (aun == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(aun, 0, sizeof(AlertPreludeThread));
/** Use the Ouput Context */
@ -829,11 +828,8 @@ OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
ctx->client = client;
output_ctx = SCMalloc(sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocated memory for OutputCtx");
exit(EXIT_FAILURE);
}
if (output_ctx == NULL)
return NULL;
output_ctx->data = ctx;
output_ctx->DeInit = AlertPreludeDeinitCtx;

@ -252,9 +252,8 @@ TmEcode AlertUnifiedAlert (ThreadVars *tv, Packet *p, void *data, PacketQueue *p
TmEcode AlertUnifiedAlertThreadInit(ThreadVars *t, void *initdata, void **data)
{
AlertUnifiedAlertThread *aun = SCMalloc(sizeof(AlertUnifiedAlertThread));
if (aun == NULL) {
if (aun == NULL)
return TM_ECODE_FAILED;
}
memset(aun, 0, sizeof(AlertUnifiedAlertThread));
if (initdata == NULL) {
@ -341,10 +340,8 @@ OutputCtx *AlertUnifiedAlertInitCtx(ConfNode *conf)
return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for OutputCtx.");
exit(EXIT_FAILURE);
}
if (output_ctx == NULL)
return NULL;
output_ctx->data = file_ctx;
output_ctx->DeInit = AlertUnifiedAlertDeInitCtx;
@ -372,8 +369,11 @@ int AlertUnifiedAlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
char *filename = NULL;
if (file_ctx->filename != NULL)
filename = file_ctx->filename;
else
else {
filename = file_ctx->filename = SCMalloc(PATH_MAX); /* XXX some sane default? */
if (filename == NULL)
return -1;
}
/* get the time so we can have a filename with seconds since epoch */
struct timeval ts;

@ -269,9 +269,8 @@ TmEcode AlertUnifiedLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
TmEcode AlertUnifiedLogThreadInit(ThreadVars *t, void *initdata, void **data)
{
AlertUnifiedLogThread *aun = SCMalloc(sizeof(AlertUnifiedLogThread));
if (aun == NULL) {
if (aun == NULL)
return TM_ECODE_FAILED;
}
memset(aun, 0, sizeof(AlertUnifiedLogThread));
if (initdata == NULL) {
@ -367,11 +366,8 @@ OutputCtx *AlertUnifiedLogInitCtx(ConfNode *conf)
return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate OutputCtx for AlertUnifiedLog");
exit(EXIT_FAILURE);
}
if (output_ctx == NULL)
return NULL;
output_ctx->data = file_ctx;
output_ctx->DeInit = AlertUnifiedLogDeInitCtx;
@ -399,8 +395,11 @@ int AlertUnifiedLogOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
char *filename = NULL;
if (file_ctx->filename != NULL)
filename = file_ctx->filename;
else
else {
filename = file_ctx->filename = SCMalloc(PATH_MAX); /* XXX some sane default? */
if (filename == NULL)
return -1;
}
/* get the time so we can have a filename with seconds since epoch */
struct timeval ts;

@ -544,9 +544,8 @@ int Unified2IPv4TypeAlert (ThreadVars *tv, Packet *p, void *data, PacketQueue *p
TmEcode Unified2AlertThreadInit(ThreadVars *t, void *initdata, void **data)
{
Unified2AlertThread *aun = SCMalloc(sizeof(Unified2AlertThread));
if (aun == NULL) {
if (aun == NULL)
return TM_ECODE_FAILED;
}
memset(aun, 0, sizeof(Unified2AlertThread));
if(initdata == NULL)
{
@ -643,11 +642,8 @@ OutputCtx *Unified2AlertInitCtx(ConfNode *conf)
return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate OutputCtx for Unified2Alert");
exit(EXIT_FAILURE);
}
if (output_ctx == NULL)
return NULL;
output_ctx->data = file_ctx;
output_ctx->DeInit = Unified2AlertDeInitCtx;
@ -675,8 +671,11 @@ int Unified2AlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
char *filename = NULL;
if (file_ctx->filename != NULL)
filename = file_ctx->filename;
else
else {
filename = file_ctx->filename = SCMalloc(PATH_MAX); /* XXX some sane default? */
if (filename == NULL)
return -1;
}
/** get the time so we can have a filename with seconds since epoch */
struct timeval ts;

@ -128,11 +128,8 @@ static int FTPParseRequestCommandLine(Flow *f, void *ftp_state, AppLayerParserSt
if (fstate->port_line != NULL)
SCFree(fstate->port_line);
fstate->port_line = SCMalloc(input_len);
if (fstate->port_line == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating"
"memory");
exit(EXIT_FAILURE);
}
if (fstate->port_line == NULL)
return 0;
fstate->port_line = memcpy(fstate->port_line, input,
input_len);
fstate->port_line_len = input_len;

@ -141,9 +141,8 @@ static void *HTPStateAlloc(void)
SCEnter();
HtpState *s = SCMalloc(sizeof(HtpState));
if (s == NULL) {
if (s == NULL)
goto error;
}
memset(s, 0x00, sizeof(HtpState));
@ -475,10 +474,8 @@ void HtpBodyAppendChunk(HtpBody *body, uint8_t *data, uint32_t len)
if (body->nchunks == 0) {
/* New chunk */
bd = (HtpBodyChunk *)SCMalloc(sizeof(HtpBodyChunk));
if (bd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed: %s", strerror(errno));
goto error;
}
if (bd == NULL)
return;
bd->len = len;
bd->data = SCMalloc(len);
@ -510,10 +507,8 @@ void HtpBodyAppendChunk(HtpBody *body, uint8_t *data, uint32_t len)
memcpy(bd->data, data, len);
} else {
bd = (HtpBodyChunk *)SCMalloc(sizeof(HtpBodyChunk));
if (bd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed: %s", strerror(errno));
goto error;
}
if (bd == NULL)
return;
bd->len = len;
bd->data = SCMalloc(len);

@ -65,9 +65,8 @@ static void *AlpResultElmtPoolAlloc(void *null)
{
AppLayerParserResultElmt *e = (AppLayerParserResultElmt *)SCMalloc
(sizeof(AppLayerParserResultElmt));
if (e == NULL) {
if (e == NULL)
return NULL;
}
memset(e, 0, sizeof(AppLayerParserResultElmt));
@ -178,19 +177,15 @@ int AlpParseFieldBySize(AppLayerParserResult *output, AppLayerParserState *pstat
if ((pstate->store_len + input_len) < size) {
if (pstate->store_len == 0) {
pstate->store = SCMalloc(input_len);
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory allocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store, input, input_len);
pstate->store_len = input_len;
} else {
pstate->store = SCRealloc(pstate->store, (input_len + pstate->store_len));
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory reallocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store+pstate->store_len, input, input_len);
pstate->store_len += input_len;
@ -209,10 +204,8 @@ int AlpParseFieldBySize(AppLayerParserResult *output, AppLayerParserState *pstat
uint32_t diff = size - pstate->store_len;
pstate->store = SCRealloc(pstate->store, (diff + pstate->store_len));
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory reallocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store+pstate->store_len, input, diff);
pstate->store_len += diff;
@ -263,10 +256,8 @@ int AlpParseFieldByEOF(AppLayerParserResult *output, AppLayerParserState *pstate
/* delimiter field not found, so store the result for the next run */
pstate->store = SCMalloc(input_len);
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory allocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store, input, input_len);
pstate->store_len = input_len;
@ -276,10 +267,8 @@ int AlpParseFieldByEOF(AppLayerParserResult *output, AppLayerParserState *pstate
SCLogDebug("store_len %" PRIu32 " and EOF", pstate->store_len);
pstate->store = SCRealloc(pstate->store, (input_len + pstate->store_len));
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory reallocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store+pstate->store_len, input, input_len);
pstate->store_len += input_len;
@ -299,10 +288,8 @@ int AlpParseFieldByEOF(AppLayerParserResult *output, AppLayerParserState *pstate
/* delimiter field not found, so store the result for the next run */
pstate->store = SCRealloc(pstate->store, (input_len + pstate->store_len));
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory reallocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store+pstate->store_len, input, input_len);
pstate->store_len += input_len;
@ -350,10 +337,8 @@ int AlpParseFieldByDelimiter(AppLayerParserResult *output, AppLayerParserState *
/* delimiter field not found, so store the result for the next run */
pstate->store = SCMalloc(input_len);
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory allocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store, input, input_len);
pstate->store_len = input_len;
@ -366,10 +351,8 @@ int AlpParseFieldByDelimiter(AppLayerParserResult *output, AppLayerParserState *
pstate->store_len, len + pstate->store_len);
pstate->store = SCRealloc(pstate->store, (len + pstate->store_len));
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory reallocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store+pstate->store_len, input, len);
pstate->store_len += len;
@ -394,10 +377,8 @@ int AlpParseFieldByDelimiter(AppLayerParserResult *output, AppLayerParserState *
* next run */
pstate->store = SCRealloc(pstate->store, (input_len +
pstate->store_len));
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory reallocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store+pstate->store_len, input, input_len);
pstate->store_len += input_len;
@ -440,10 +421,8 @@ int AlpParseFieldByDelimiter(AppLayerParserResult *output, AppLayerParserState *
/* delimiter field not found, so store the result for the next run */
pstate->store = SCRealloc(pstate->store, (input_len + pstate->store_len));
if (pstate->store == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Memory reallocation failed!");
if (pstate->store == NULL)
SCReturnInt(-1);
}
memcpy(pstate->store+pstate->store_len, input, input_len);
pstate->store_len += input_len;
@ -960,8 +939,8 @@ void AppLayerParsersInitPostProcess(void)
(al_proto_table[u16].map_size *
sizeof(AppLayerLocalMap *));
if (al_proto_table[u16].map == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "memory error");
exit(1);
SCLogError(SC_ERR_FATAL, "Fatal error encountered in AppLayerParsersInitPostProcess. Exiting...");
exit(EXIT_FAILURE);
}
memset(al_proto_table[u16].map, 0, al_proto_table[u16].map_size *
sizeof(AppLayerLocalMap *));
@ -981,8 +960,8 @@ void AppLayerParsersInitPostProcess(void)
if (parser_local_id < al_proto_table[u16].map_size) {
al_proto_table[u16].map[parser_local_id] = SCMalloc(sizeof(AppLayerLocalMap));
if (al_proto_table[u16].map[parser_local_id] == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "XXX memory error");
exit(1);
SCLogError(SC_ERR_FATAL, "Fatal error encountered in AppLayerParsersInitPostProcess. Exiting...");
exit(EXIT_FAILURE);
}
al_proto_table[u16].map[parser_local_id]->parser_id = u;

@ -94,6 +94,8 @@ ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq)
if (inseq) {
ConfNode *seq_node = ConfNodeNew();
seq_node->name = SCCalloc(1, DEFAULT_NAME_LEN);
if (seq_node->name == NULL)
return -1;
snprintf(seq_node->name, DEFAULT_NAME_LEN, "%d", seq_idx++);
seq_node->val = SCStrdup(value);
TAILQ_INSERT_TAIL(&parent->head, seq_node, next);
@ -142,6 +144,8 @@ ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq)
ConfNode *seq_node = ConfNodeNew();
seq_node->is_seq = 1;
seq_node->name = SCCalloc(1, DEFAULT_NAME_LEN);
if (seq_node->name == NULL)
return -1;
snprintf(seq_node->name, DEFAULT_NAME_LEN, "%d", seq_idx++);
TAILQ_INSERT_TAIL(&node->head, seq_node, next);
if (ConfYamlParse(parser, seq_node, 0) != 0)

@ -78,9 +78,7 @@ ConfNodeNew(void)
new = SCCalloc(1, sizeof(*new));
if (new == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Error allocating memory for new configuration node");
exit(EXIT_FAILURE);
return NULL;
}
/* By default we allow an override. */
new->allow_override = 1;

@ -272,8 +272,7 @@ static char *SCPerfGetLogFilename(void)
log_dir = DEFAULT_LOG_DIR;
if ( (log_filename = SCMalloc(PATH_MAX)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
return NULL;
}
if (snprintf(log_filename, PATH_MAX, "%s/%s", log_dir,
@ -294,7 +293,7 @@ static char *SCPerfGetLogFilename(void)
static void SCPerfInitOPCtx(void)
{
if ( (sc_perf_op_ctx = SCMalloc(sizeof(SCPerfOPIfaceContext))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCPerfInitOPCtx. Exiting...");
exit(EXIT_FAILURE);
}
memset(sc_perf_op_ctx, 0, sizeof(SCPerfOPIfaceContext));
@ -671,24 +670,20 @@ static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name,
return(temp->id);
/* if we reach this point we don't have a counter registered by this cname */
if ( (pc = SCMalloc(sizeof(SCPerfCounter))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (pc = SCMalloc(sizeof(SCPerfCounter))) == NULL)
return 0;
memset(pc, 0, sizeof(SCPerfCounter));
if ( (pc->name = SCMalloc(sizeof(SCPerfCounterName))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCFree(pc);
exit(EXIT_FAILURE);
return 0;
}
memset(pc->name, 0, sizeof(SCPerfCounterName));
if ( (pc->value = SCMalloc(sizeof(SCPerfCounterValue))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCFree(pc->name);
SCFree(pc);
exit(EXIT_FAILURE);
return 0;
}
memset(pc->value, 0, sizeof(SCPerfCounterValue));
@ -711,10 +706,8 @@ static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name,
exit(EXIT_FAILURE);
}
if ( (pc->type_q = SCMalloc(sizeof(SCPerfCounterTypeQ))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (pc->type_q = SCMalloc(sizeof(SCPerfCounterTypeQ))) == NULL)
return 0;
memset(pc->type_q, 0, sizeof(SCPerfCounterTypeQ));
pc->type_q->type = type_q;
@ -742,10 +735,8 @@ static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name,
break;
}
if ( (pc->value->cvalue = SCMalloc(pc->value->size)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (pc->value->cvalue = SCMalloc(pc->value->size)) == NULL)
return 0;
memset(pc->value->cvalue, 0, pc->value->size);
/* display flag which specifies if the counter should be displayed or not */
@ -1001,10 +992,8 @@ static int SCPerfOutputCounterFileIface()
pctmi = sc_perf_op_ctx->pctmi;
while (pctmi != NULL) {
if ( (pc_heads = SCMalloc(pctmi->size * sizeof(SCPerfCounter *))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (pc_heads = SCMalloc(pctmi->size * sizeof(SCPerfCounter *))) == NULL)
return 0;
memset(pc_heads, 0, pctmi->size * sizeof(SCPerfCounter **));
for (u = 0; u < pctmi->size; u++) {
@ -1369,14 +1358,14 @@ int SCPerfAddToClubbedTMTable(char *tm_name, SCPerfContext *pctx)
/* get me the bugger who wrote this junk of a code :P */
if (pctmi == NULL) {
if ( (temp = SCMalloc(sizeof(SCPerfClubTMInst))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(0);
}
if ( (temp = SCMalloc(sizeof(SCPerfClubTMInst))) == NULL)
return 0;
memset(temp, 0, sizeof(SCPerfClubTMInst));
temp->size++;
temp->head = SCRealloc(temp->head, temp->size * sizeof(SCPerfContext **));
if (temp->head == NULL)
return 0;
temp->head[0] = pctx;
temp->tm_name = SCStrdup(tm_name);
@ -1400,6 +1389,8 @@ int SCPerfAddToClubbedTMTable(char *tm_name, SCPerfContext *pctx)
pctmi->head = SCRealloc(pctmi->head,
(pctmi->size + 1) * sizeof(SCPerfContext **));
if (pctmi->head == NULL)
return 0;
hpctx = pctmi->head;
hpctx[pctmi->size] = pctx;
@ -1449,16 +1440,12 @@ SCPerfCounterArray *SCPerfGetCounterArrayRange(uint16_t s_id, uint16_t e_id,
return NULL;
}
if ( (pca = SCMalloc(sizeof(SCPerfCounterArray))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (pca = SCMalloc(sizeof(SCPerfCounterArray))) == NULL)
return NULL;
memset(pca, 0, sizeof(SCPerfCounterArray));
if ( (pca->head = SCMalloc(sizeof(SCPCAElem) * (e_id - s_id + 2))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (pca->head = SCMalloc(sizeof(SCPCAElem) * (e_id - s_id + 2))) == NULL)
return NULL;
memset(pca->head, 0, sizeof(SCPCAElem) * (e_id - s_id + 2));
pc = pctx->head;

@ -292,6 +292,8 @@ DefragFragNew(void *arg)
Frag *frag;
frag = SCCalloc(1, sizeof(*frag));
if (frag == NULL)
return NULL;
frag->dc = dc;
return (void *)frag;

@ -96,10 +96,8 @@ static int DetectAckSetup(DetectEngineCtx *de_ctx, Signature *s, char *optstr)
SigMatch *sm = NULL;
data = SCMalloc(sizeof(DetectAckData));
if (data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (data == NULL)
goto error;
}
sm = SigMatchAlloc();
if (sm == NULL) {

@ -389,10 +389,8 @@ DetectBytejumpData *DetectBytejumpParse(char *optstr)
/* Initialize the data */
data = SCMalloc(sizeof(DetectBytejumpData));
if (data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,"malloc failed %s", strerror(errno));
if (data == NULL)
goto error;
}
data->base = DETECT_BYTEJUMP_BASE_UNSET;
data->flags = 0;
data->multiplier = 1;

@ -397,10 +397,8 @@ DetectBytetestData *DetectBytetestParse(char *optstr)
/* Initialize the data */
data = SCMalloc(sizeof(DetectBytetestData));
if (data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed");
if (data == NULL)
goto error;
}
data->base = DETECT_BYTETEST_BASE_UNSET;
data->flags = 0;

@ -81,10 +81,8 @@ DetectContentData *DetectContentParse (char *contentstr)
}
cd = SCMalloc(sizeof(DetectContentData));
if (cd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed");
if (cd == NULL)
goto error;
}
memset(cd, 0, sizeof(DetectContentData));
/* skip the first spaces */

@ -260,10 +260,8 @@ static int DetectIPV4CsumSetup(DetectEngineCtx *de_ctx, Signature *s, char *csum
sm->type = DETECT_IPV4_CSUM;
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL)
goto error;
}
memset(cd, 0, sizeof(DetectCsumData));
if (DetectCsumParseArg(csum_str, cd) == 0)
@ -354,10 +352,8 @@ static int DetectTCPV4CsumSetup(DetectEngineCtx *de_ctx, Signature *s, char *csu
sm->type = DETECT_TCPV4_CSUM;
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL)
goto error;
}
memset(cd, 0, sizeof(DetectCsumData));
if (DetectCsumParseArg(csum_str, cd) == 0)
@ -448,10 +444,8 @@ static int DetectTCPV6CsumSetup(DetectEngineCtx *de_ctx, Signature *s, char *csu
sm->type = DETECT_TCPV6_CSUM;
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL)
goto error;
}
memset(cd, 0, sizeof(DetectCsumData));
if (DetectCsumParseArg(csum_str, cd) == 0)
@ -542,10 +536,8 @@ static int DetectUDPV4CsumSetup(DetectEngineCtx *de_ctx, Signature *s, char *csu
sm->type = DETECT_UDPV4_CSUM;
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL)
goto error;
}
memset(cd, 0, sizeof(DetectCsumData));
if (DetectCsumParseArg(csum_str, cd) == 0)
@ -636,10 +628,8 @@ static int DetectUDPV6CsumSetup(DetectEngineCtx *de_ctx, Signature *s, char *csu
sm->type = DETECT_UDPV6_CSUM;
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL)
goto error;
}
memset(cd, 0, sizeof(DetectCsumData));
if (DetectCsumParseArg(csum_str, cd) == 0)
@ -729,10 +719,8 @@ static int DetectICMPV4CsumSetup(DetectEngineCtx *de_ctx, Signature *s, char *cs
sm->type = DETECT_ICMPV4_CSUM;
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL)
goto error;
}
memset(cd, 0, sizeof(DetectCsumData));
if (DetectCsumParseArg(csum_str, cd) == 0)
@ -820,10 +808,8 @@ static int DetectICMPV6CsumSetup(DetectEngineCtx *de_ctx, Signature *s, char *cs
sm->type = DETECT_ICMPV6_CSUM;
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (cd = SCMalloc(sizeof(DetectCsumData))) == NULL)
goto error;
}
memset(cd, 0, sizeof(DetectCsumData));
if (DetectCsumParseArg(csum_str, cd) == 0)

@ -123,10 +123,8 @@ static inline DetectDceIfaceData *DetectDceIfaceArgParse(const char *arg)
goto error;
}
if ( (did = SCMalloc(sizeof(DetectDceIfaceData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (did = SCMalloc(sizeof(DetectDceIfaceData))) == NULL)
goto error;
}
memset(did, 0, sizeof(DetectDceIfaceData));
/* retrieve the iface uuid string. iface uuid is a compulsion in the keyword */

@ -104,10 +104,8 @@ static inline DetectDceOpnumRange *DetectDceOpnumAllocDetectDceOpnumRange(void)
{
DetectDceOpnumRange *dor = NULL;
if ( (dor = SCMalloc(sizeof(DetectDceOpnumRange))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (dor = SCMalloc(sizeof(DetectDceOpnumRange))) == NULL)
return NULL;
memset(dor, 0, sizeof(DetectDceOpnumRange));
dor->range1 = dor->range2 = DCE_OPNUM_RANGE_UNINITIALIZED;
@ -154,10 +152,8 @@ static inline DetectDceOpnumData *DetectDceOpnumArgParse(const char *arg)
goto error;
}
if ( (dod = SCMalloc(sizeof(DetectDceOpnumData))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (dod = SCMalloc(sizeof(DetectDceOpnumData))) == NULL)
goto error;
}
memset(dod, 0, sizeof(DetectDceOpnumData));
if ( (dup_str = SCStrdup(pcre_sub_str)) == NULL) {
@ -177,6 +173,8 @@ static inline DetectDceOpnumData *DetectDceOpnumArgParse(const char *arg)
dup_str = comma_token + 1;
dor = DetectDceOpnumAllocDetectDceOpnumRange();
if (dor == NULL)
goto error;
if ((hyphen_token = index(dup_str_temp, '-')) != NULL) {
hyphen_token[0] = '\0';
@ -206,6 +204,8 @@ static inline DetectDceOpnumData *DetectDceOpnumArgParse(const char *arg)
}
dor = DetectDceOpnumAllocDetectDceOpnumRange();
if (dor == NULL)
goto error;
if ( (hyphen_token = index(dup_str, '-')) != NULL) {
hyphen_token[0] = '\0';

@ -148,10 +148,8 @@ DetectDecodeEventData *DetectDecodeEventParse (char *rawstr)
goto error;
de = SCMalloc(sizeof(DetectDecodeEventData));
if (de == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Malloc failed");
if (de == NULL)
goto error;
}
de->event = DEvents[i].code;
return de;

@ -136,11 +136,10 @@ DetectThresholdData *DetectDetectionFilterParse (char *rawstr) {
}
df = SCMalloc(sizeof(DetectDetectionFilterData));
if (df == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed: %s", strerror(errno));
if (df == NULL)
goto error;
}
memset(df, 0, sizeof(DetectDetectionFilterData));
memset(df,0,sizeof(DetectDetectionFilterData));
df->type = TYPE_DETECTION;

@ -176,10 +176,8 @@ DetectDsizeData *DetectDsizeParse (char *rawstr)
SCLogDebug("value2 \"%s\"", value2);
dd = SCMalloc(sizeof(DetectDsizeData));
if (dd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (dd == NULL)
goto error;
}
dd->dsize = 0;
dd->dsize2 = 0;

@ -981,10 +981,8 @@ int DetectAddressParse2(DetectAddressHead *gh, DetectAddressHead *ghn, char *s,
temp_rule_var_address = rule_var_address;
if ((negate + n_set) % 2) {
temp_rule_var_address = SCMalloc(strlen(rule_var_address) + 3);
if (temp_rule_var_address == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (temp_rule_var_address == NULL)
goto error;
}
snprintf(temp_rule_var_address, strlen(rule_var_address) + 3,
"[%s]", rule_var_address);
}
@ -1025,10 +1023,8 @@ int DetectAddressParse2(DetectAddressHead *gh, DetectAddressHead *ghn, char *s,
temp_rule_var_address = rule_var_address;
if ((negate + n_set) % 2) {
temp_rule_var_address = SCMalloc(strlen(rule_var_address) + 3);
if (temp_rule_var_address == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (temp_rule_var_address == NULL)
goto error;
}
snprintf(temp_rule_var_address, strlen(rule_var_address) + 3,
"[%s]", rule_var_address);
}

@ -67,10 +67,8 @@ IPOnlyCIDRItem *IPOnlyCIDRItemNew() {
IPOnlyCIDRItem *item = NULL;
item = SCMalloc(sizeof(IPOnlyCIDRItem));
if (item == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating IPOnlyCIDRItem");
exit(EXIT_FAILURE);
}
if (item == NULL)
return NULL;
memset(item, 0, sizeof(IPOnlyCIDRItem));
return item;
@ -250,16 +248,16 @@ SigNumArray *SigNumArrayNew(DetectEngineCtx *de_ctx,
{
SigNumArray *new = SCMalloc(sizeof(SigNumArray));
if (new == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,"Error allocating memory");
if (new == NULL){
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigNumArrayNew. Exiting...");
exit(EXIT_FAILURE);
}
memset(new, 0, sizeof(SigNumArray));
new->array = SCMalloc(io_ctx->max_idx / 8 + 1);
if (new->array == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigNumArrayNew. Exiting...");
exit(EXIT_FAILURE);
}
memset(new->array, 0, io_ctx->max_idx / 8 + 1);
@ -282,7 +280,7 @@ SigNumArray *SigNumArrayCopy(SigNumArray *orig) {
SigNumArray *new = SCMalloc(sizeof(SigNumArray));
if (new == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,"Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigNumArrayCopy. Exiting...");
exit(EXIT_FAILURE);
}
@ -291,7 +289,7 @@ SigNumArray *SigNumArrayCopy(SigNumArray *orig) {
new->array = SCMalloc(orig->size);
if (new->array == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigNumArrayCopy. Exiting...");
exit(EXIT_FAILURE);
}
@ -383,7 +381,6 @@ IPOnlyCIDRItem *IPOnlyCIDRListParse2(char *s, int negate)
temp_rule_var_address = SCMalloc(strlen(rule_var_address) + 3);
if (temp_rule_var_address == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
goto error;
}
@ -405,6 +402,8 @@ IPOnlyCIDRItem *IPOnlyCIDRListParse2(char *s, int negate)
address[x - 1] = '\0';
subhead = IPOnlyCIDRItemNew();
if (subhead == NULL)
goto error;
if (!((negate + n_set) % 2))
subhead->negated = 0;
@ -441,7 +440,6 @@ IPOnlyCIDRItem *IPOnlyCIDRListParse2(char *s, int negate)
if ((negate + n_set) % 2) {
temp_rule_var_address = SCMalloc(strlen(rule_var_address) + 3);
if (temp_rule_var_address == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
goto error;
}
snprintf(temp_rule_var_address, strlen(rule_var_address) + 3,
@ -457,6 +455,8 @@ IPOnlyCIDRItem *IPOnlyCIDRListParse2(char *s, int negate)
SCFree(temp_rule_var_address);
} else {
subhead = IPOnlyCIDRItemNew();
if (subhead == NULL)
goto error;
if (!((negate + n_set) % 2))
subhead->negated = 0;
@ -600,6 +600,8 @@ int IPOnlyCIDRItemParseSingle(IPOnlyCIDRItem *dd, char *str)
BUG_ON(dd->family == 0);
dd->next = IPOnlyCIDRItemNew();
if (dd->next == NULL)
return -1;
IPOnlyCIDRItemParseSingle(dd->next, "::/0");
BUG_ON(dd->family == 0);
@ -701,6 +703,8 @@ int IPOnlyCIDRItemParseSingle(IPOnlyCIDRItem *dd, char *str)
if (first < last) {
for (first++; first <= last; first++) {
IPOnlyCIDRItem *new = IPOnlyCIDRItemNew();
if (new == NULL)
goto error;
dd->next = new;
new->negated = dd->negated;
new->family= dd->family;
@ -801,7 +805,7 @@ void IPOnlyInit(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx) {
io_ctx->sig_init_size = DetectEngineGetMaxSigId(de_ctx) / 8 + 1;
if ( (io_ctx->sig_init_array = SCMalloc(io_ctx->sig_init_size)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in IPOnlyInit. Exiting...");
exit(EXIT_FAILURE);
}
@ -828,6 +832,10 @@ void DetectEngineIPOnlyThreadInit(DetectEngineCtx *de_ctx,
/* initialize the signature bitarray */
io_tctx->sig_match_size = de_ctx->io_ctx.max_idx / 8 + 1;
io_tctx->sig_match_array = SCMalloc(io_tctx->sig_match_size);
if (io_tctx->sig_match_array == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in DetectEngineIPOnlyThreadInit. Exiting...");
exit(EXIT_FAILURE);
}
memset(io_tctx->sig_match_array, 0, io_tctx->sig_match_size);
}

@ -364,10 +364,8 @@ static int PatternMatchPreprarePopulateMpm(DetectEngineCtx *de_ctx, SigGroupHead
uint32_t *fast_pattern = NULL;
fast_pattern = (uint32_t *)SCMalloc(sgh->sig_cnt * sizeof(uint32_t));
if (fast_pattern == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (fast_pattern == NULL)
return -1;
}
memset(fast_pattern, 0, sgh->sig_cnt * sizeof(uint32_t));
HashTable *ht = HashTableInit(4096, ContentHashFunc, ContentHashCompareFunc, ContentHashFree);

@ -77,10 +77,8 @@ void DetectPortRegister(void) {
*/
DetectPort *DetectPortInit(void) {
DetectPort *dp = SCMalloc(sizeof(DetectPort));
if (dp == NULL) {
// SCLogDebug(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (dp == NULL)
return NULL;
}
memset(dp, 0, sizeof(DetectPort));
detect_port_memory += sizeof(DetectPort);
@ -1064,10 +1062,8 @@ static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s,
temp_rule_var_port = rule_var_port;
if (negate == 1 || n_set == 1) {
temp_rule_var_port = SCMalloc(strlen(rule_var_port) + 3);
if (temp_rule_var_port == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (temp_rule_var_port == NULL)
goto error;
}
snprintf(temp_rule_var_port, strlen(rule_var_port) + 3,
"[%s]", rule_var_port);
}
@ -1115,10 +1111,8 @@ static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s,
temp_rule_var_port = rule_var_port;
if ((negate + n_set) % 2) {
temp_rule_var_port = SCMalloc(strlen(rule_var_port) + 3);
if (temp_rule_var_port == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (temp_rule_var_port == NULL)
goto error;
}
snprintf(temp_rule_var_port, strlen(rule_var_port) + 3,
"[%s]", rule_var_port);
}

@ -63,10 +63,8 @@ void DetectProtoRegister (void)
DetectProto *DetectProtoInit(void)
{
DetectProto *dp = SCMalloc(sizeof(DetectProto));
if (dp == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "error in memory allocation");
if (dp == NULL)
return NULL;
}
memset(dp,0,sizeof(DetectProto));
return dp;

@ -104,10 +104,8 @@ void SigGroupHeadInitDataFree(SigGroupHeadInitData *sghid) {
static SigGroupHead *SigGroupHeadAlloc(uint32_t size)
{
SigGroupHead *sgh = SCMalloc(sizeof(SigGroupHead));
if (sgh == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (sgh == NULL)
return NULL;
}
memset(sgh, 0, sizeof(SigGroupHead));
sgh->init = SigGroupHeadInitDataAlloc(size);
@ -119,10 +117,8 @@ static SigGroupHead *SigGroupHeadAlloc(uint32_t size)
/* initialize the signature bitarray */
sgh->sig_size = size;
if ( (sgh->sig_array = SCMalloc(sgh->sig_size)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if ( (sgh->sig_array = SCMalloc(sgh->sig_size)) == NULL)
goto error;
}
memset(sgh->sig_array, 0, sgh->sig_size);
detect_siggroup_sigarray_init_cnt++;

@ -79,7 +79,7 @@ static void SCSigRegisterSignatureOrderingFunc(DetectEngineCtx *de_ctx,
return;
if ( (temp = SCMalloc(sizeof(SCSigOrderFunc))) == NULL) {
printf("Error allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCSigRegisterSignatureOrderingFunc. Exiting...");
exit(EXIT_FAILURE);
}
memset(temp, 0, sizeof(SCSigOrderFunc));
@ -785,25 +785,19 @@ static inline SCSigSignatureWrapper *SCSigAllocSignatureWrapper(Signature *sig)
SCSigSignatureWrapper *sw = NULL;
int i = 0;
if ( (sw = SCMalloc(sizeof(SCSigSignatureWrapper))) == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
}
if ( (sw = SCMalloc(sizeof(SCSigSignatureWrapper))) == NULL)
return NULL;
memset(sw, 0, sizeof(SCSigSignatureWrapper));
sw->sig = sig;
if ( (sw->user = SCMalloc(SC_RADIX_USER_DATA_MAX * sizeof(int *))) == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
}
if ( (sw->user = SCMalloc(SC_RADIX_USER_DATA_MAX * sizeof(int *))) == NULL)
return NULL;
memset(sw->user, 0, SC_RADIX_USER_DATA_MAX * sizeof(int *));
for (i = 0; i < SC_RADIX_USER_DATA_MAX; i++) {
if ( (sw->user[i] = SCMalloc(sizeof(int))) == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
}
if ( (sw->user[i] = SCMalloc(sizeof(int))) == NULL)
return NULL;
memset(sw->user[i], 0, sizeof(int));
}

@ -265,10 +265,8 @@ int PacketAlertThreshold(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx
/* setup the Entry we use to search our hash with */
ste = SCMalloc(sizeof(DetectThresholdEntry));
if (ste == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s", strerror(errno));
SCReturnInt(ret);
}
if (ste == NULL)
SCReturnInt(0);
memset(ste, 0x00, sizeof(ste));
if (PKT_IS_IPV4(p))

@ -56,9 +56,8 @@ DetectEngineCtx *DetectEngineCtxInit(void) {
DetectEngineCtx *de_ctx;
de_ctx = SCMalloc(sizeof(DetectEngineCtx));
if (de_ctx == NULL) {
if (de_ctx == NULL)
goto error;
}
memset(de_ctx,0,sizeof(DetectEngineCtx));
@ -435,9 +434,8 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data) {
return TM_ECODE_FAILED;
DetectEngineThreadCtx *det_ctx = SCMalloc(sizeof(DetectEngineThreadCtx));
if (det_ctx == NULL) {
if (det_ctx == NULL)
return TM_ECODE_FAILED;
}
memset(det_ctx, 0, sizeof(DetectEngineThreadCtx));
det_ctx->de_ctx = de_ctx;
@ -479,10 +477,8 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data) {
uint8_t disp_outq_name_len = (strlen(tv->name) + strlen(cuda_outq_name) + 1);
char *disp_outq_name = SCMalloc(disp_outq_name_len * sizeof(char));
if (disp_outq_name == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if (disp_outq_name == NULL)
goto error;
strcpy(disp_outq_name, tv->name);
strcpy(disp_outq_name + strlen(tv->name), cuda_outq_name);
disp_outq_name[disp_outq_name_len] = '\0';

@ -206,10 +206,8 @@ static DetectFlagsData *DetectFlagsParse (char *rawstr)
}
de = SCMalloc(sizeof(DetectFlagsData));
if (de == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (de == NULL)
goto error;
}
memset(de,0,sizeof(DetectFlagsData));

@ -176,10 +176,8 @@ DetectFlowData *DetectFlowParse (char *flowstr)
}
fd = SCMalloc(sizeof(DetectFlowData));
if (fd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (fd == NULL)
goto error;
}
fd->flags = 0;
fd->match_cnt = 0;

@ -219,10 +219,8 @@ int DetectFlowbitSetup (DetectEngineCtx *de_ctx, Signature *s, char *rawstr)
}
cd = SCMalloc(sizeof(DetectFlowbitsData));
if (cd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "DetectFlowbitsSetup malloc failed");
if (cd == NULL)
goto error;
}
if (fb_name != NULL) {
cd->idx = VariableNameGetIdx(de_ctx,fb_name,DETECT_FLOWBITS);

@ -283,10 +283,8 @@ DetectFlowintData *DetectFlowintParse(DetectEngineCtx *de_ctx,
}
sfd = SCMalloc(sizeof(DetectFlowintData));
if (sfd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (sfd == NULL)
goto error;
}
/* If we need another arg, check it out(isset doesn't need another arg) */
if (modifier != FLOWINT_MODIFIER_ISSET && modifier != FLOWINT_MODIFIER_NOTSET) {

@ -151,10 +151,8 @@ static int DetectFlowvarSetup (DetectEngineCtx *de_ctx, Signature *s, char *raws
}
cd = SCMalloc(sizeof(DetectFlowvarData));
if (cd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (cd == NULL)
goto error;
}
char converted = 0;

@ -188,10 +188,8 @@ static DetectFragBitsData *DetectFragBitsParse (char *rawstr)
}
de = SCMalloc(sizeof(DetectFragBitsData));
if (de == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (de == NULL)
goto error;
}
memset(de,0,sizeof(DetectFragBitsData));

@ -156,10 +156,8 @@ DetectFragOffsetData *DetectFragOffsetParse (char *fragoffsetstr) {
}
fragoff = SCMalloc(sizeof(DetectFragOffsetData));
if (fragoff == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (fragoff == NULL)
goto error;
}
fragoff->frag_off = 0;
fragoff->mode = 0;

@ -124,9 +124,8 @@ int DetectHttpClientBodyMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx,
/* club all the chunks into one whole buffer and call the SPM on the buffer */
while (cur != NULL) {
total_chunks_len += cur->len;
if ( (chunks_buffer = realloc(chunks_buffer, total_chunks_len)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
if ( (chunks_buffer = SCRealloc(chunks_buffer, total_chunks_len)) == NULL) {
return 0;
}
memcpy(chunks_buffer + total_chunks_len - cur->len, cur->data, cur->len);
cur = cur->next;
@ -210,10 +209,8 @@ int DetectHttpClientBodySetup(DetectEngineCtx *de_ctx, Signature *s, char *arg)
/* setup the HttpClientBodyData's data from content data structure's data */
hcbd = SCMalloc(sizeof(DetectHttpClientBodyData));
if (hcbd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc() failed");
if (hcbd == NULL)
goto error;
}
memset(hcbd, 0, sizeof(DetectHttpClientBodyData));
/* transfer the pattern details from the content struct to the clientbody struct */

@ -225,10 +225,8 @@ static int DetectHttpCookieSetup (DetectEngineCtx *de_ctx, Signature *s, char *s
/* Setup the HttpCookie data from Content data structure */
hd = SCMalloc(sizeof(DetectHttpCookieData));
if (hd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed");
if (hd == NULL)
goto error;
}
memset(hd, 0, sizeof(DetectHttpCookieData));
hd->data_len = ((DetectContentData *)pm->ctx)->content_len;

@ -196,10 +196,8 @@ static int DetectHttpMethodSetup(DetectEngineCtx *de_ctx, Signature *s, char *st
}
data = SCMalloc(sizeof(DetectHttpMethodData));
if (data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed");
if (data == NULL)
goto error;
}
data->content_len = ((DetectContentData *)pm->ctx)->content_len;
data->content = ((DetectContentData *)pm->ctx)->content;

@ -166,10 +166,8 @@ DetectIcmpIdData *DetectIcmpIdParse (char *icmpidstr) {
}
iid = SCMalloc(sizeof(DetectIcmpIdData));
if (iid == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (iid == NULL)
goto error;
}
iid->id = 0;
if (substr[0]!= NULL && strlen(substr[0]) != 0) {

@ -166,10 +166,8 @@ DetectIcmpSeqData *DetectIcmpSeqParse (char *icmpseqstr) {
}
iseq = SCMalloc(sizeof(DetectIcmpSeqData));
if (iseq == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (iseq == NULL)
goto error;
}
iseq->seq = 0;

@ -159,10 +159,8 @@ DetectICodeData *DetectICodeParse(char *icodestr) {
}
icd = SCMalloc(sizeof(DetectICodeData));
if (icd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (icd == NULL)
goto error;
}
icd->code1 = 0;
icd->code2 = 0;
icd->mode = 0;

@ -161,10 +161,8 @@ DetectIdData *DetectIdParse (char *idstr)
/* We have a correct id option */
id_d = SCMalloc(sizeof(DetectIdData));
if (id_d == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (id_d == NULL)
goto error;
}
orig = SCStrdup((char*)str_ptr);
tmp_str=orig;

@ -161,10 +161,8 @@ DetectIpOptsData *DetectIpOptsParse (char *rawstr)
goto error;
de = SCMalloc(sizeof(DetectIpOptsData));
if (de == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (de == NULL)
goto error;
}
de->ipopt = DIpOpts[i].code;

@ -126,10 +126,8 @@ static DetectIPProtoData *DetectIPProtoParse(const char *optstr)
/* Initialize the data */
data = SCMalloc(sizeof(DetectIPProtoData));
if (data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (data == NULL)
goto error;
}
data->op = DETECT_IPPROTO_OP_EQ;
data->proto = 0;

@ -172,10 +172,8 @@ DetectIsdataatData *DetectIsdataatParse (char *isdataatstr)
}
idad = SCMalloc(sizeof(DetectIsdataatData));
if (idad == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (idad == NULL)
goto error;
}
idad->flags = 0;
idad->dataat = 0;

@ -159,10 +159,8 @@ DetectITypeData *DetectITypeParse(char *itypestr) {
}
itd = SCMalloc(sizeof(DetectITypeData));
if (itd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (itd == NULL)
goto error;
}
itd->type1 = 0;
itd->type2 = 0;
itd->mode = 0;

@ -81,7 +81,7 @@ static SigMatch *SigMatchGetLastNocasePattern(Signature *s) {
if (co_sm != NULL) {
sm_list_count++;
if ( (sm_list = SCRealloc(sm_list, sizeof(SigMatch *) * sm_list_count)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigMatchGetLastNocasePattern. Exiting...");
exit(EXIT_FAILURE);
}
sm_list[sm_list_count - 1] = co_sm;
@ -89,7 +89,7 @@ static SigMatch *SigMatchGetLastNocasePattern(Signature *s) {
if (ur_sm != NULL) {
sm_list_count++;
if ( (sm_list = SCRealloc(sm_list, sizeof(SigMatch *) * sm_list_count)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigMatchGetLastNocasePattern. Exiting...");
exit(EXIT_FAILURE);
}
sm_list[sm_list_count - 1] = ur_sm;
@ -97,7 +97,7 @@ static SigMatch *SigMatchGetLastNocasePattern(Signature *s) {
if (hcbd_sm != NULL) {
sm_list_count++;
if ( (sm_list = SCRealloc(sm_list, sizeof(SigMatch *) * sm_list_count)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigMatchGetLastNocasePattern. Exiting...");
exit(EXIT_FAILURE);
}
sm_list[sm_list_count - 1] = hcbd_sm;
@ -105,7 +105,7 @@ static SigMatch *SigMatchGetLastNocasePattern(Signature *s) {
if (hcd_sm != NULL) {
sm_list_count++;
if ( (sm_list = SCRealloc(sm_list, sizeof(SigMatch *) * sm_list_count)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SigMatchGetLastNocasePattern. Exiting...");
exit(EXIT_FAILURE);
}
sm_list[sm_list_count - 1] = hcd_sm;

@ -421,10 +421,8 @@ DetectPcreData *DetectPcreParse (char *regexstr)
//printf("ret %" PRId32 " re \'%s\', op \'%s\'\n", ret, re, op);
pd = SCMalloc(sizeof(DetectPcreData));
if (pd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (pd == NULL)
goto error;
}
memset(pd, 0, sizeof(DetectPcreData));
if (negate)
@ -524,6 +522,8 @@ DetectPcreData *DetectPcreParse (char *regexstr)
#endif /* NO_PCRE_MATCH_RLIMIT */
}
} else {
goto error;
}
if (re != NULL) SCFree(re);

@ -147,10 +147,8 @@ static int DetectPktvarSetup (DetectEngineCtx *de_ctx, Signature *s, char *rawst
}
cd = SCMalloc(sizeof(DetectPktvarData));
if (cd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (cd == NULL)
goto error;
}
char converted = 0;

@ -198,10 +198,8 @@ DetectRpcData *DetectRpcParse (char *rpcstr)
}
rd = SCMalloc(sizeof(DetectRpcData));
if (rd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC ,"malloc failed");
if (rd == NULL)
goto error;
}
rd->flags = 0;
rd->program = 0;
rd->program_version = 0;

@ -96,10 +96,8 @@ static int DetectSeqSetup (DetectEngineCtx *de_ctx, Signature *s, char *optstr)
SigMatch *sm = NULL;
data = SCMalloc(sizeof(DetectSeqData));
if (data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (data == NULL)
goto error;
}
sm = SigMatchAlloc();
if (sm == NULL) {

@ -231,10 +231,8 @@ DetectStreamSizeData *DetectStreamSizeParse (char *streamstr) {
value = (char *)str_ptr;
sd = SCMalloc(sizeof(DetectStreamSizeData));
if (sd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (sd == NULL)
goto error;
}
sd->ssize = 0;
sd->flags = 0;

@ -143,10 +143,8 @@ static DetectThresholdData *DetectThresholdParse (char *rawstr)
}
de = SCMalloc(sizeof(DetectThresholdData));
if (de == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (de == NULL)
goto error;
}
memset(de,0,sizeof(DetectThresholdData));
@ -586,10 +584,8 @@ static int DetectThresholdTestSig3(void) {
/* setup the Entry we use to search our hash with */
ste = SCMalloc(sizeof(DetectThresholdEntry));
if (ste == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s", strerror(errno));
if (ste == NULL)
goto end;
}
memset(ste, 0x00, sizeof(ste));
if (PKT_IS_IPV4(&p))

@ -172,10 +172,8 @@ DetectTlsVersionData *DetectTlsVersionParse (char *str)
/* We have a correct id option */
tls = SCMalloc(sizeof(DetectTlsVersionData));
if (tls == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (tls == NULL)
goto error;
}
orig = SCStrdup((char*)str_ptr);
tmp_str=orig;

@ -170,10 +170,8 @@ DetectTtlData *DetectTtlParse (char *ttlstr) {
SCLogDebug("Arg3 \"%s\"", arg3);
ttld = SCMalloc(sizeof (DetectTtlData));
if (ttld == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (ttld == NULL)
goto error;
}
ttld->ttl1 = 0;
ttld->ttl2 = 0;

@ -96,6 +96,8 @@ void DetectUricontentPrint(DetectUricontentData *cd)
return;
}
char *tmpstr = SCMalloc(sizeof(char) * cd->uricontent_len + 1);
if (tmpstr == NULL)
return;
if (tmpstr != NULL) {
for (i = 0; i < cd->uricontent_len; i++) {
@ -176,10 +178,8 @@ DetectUricontentData *DoDetectUricontentSetup (char * contentstr)
}
cd = SCMalloc(sizeof(DetectUricontentData));
if (cd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed");
if (cd == NULL)
goto error;
}
memset(cd,0,sizeof(DetectUricontentData));
/* skip the first spaces */

@ -213,10 +213,8 @@ DetectUrilenData *DetectUrilenParse (char *urilenstr)
SCLogDebug("Arg4 \"%s\"", arg4);
urilend = SCMalloc(sizeof (DetectUrilenData));
if (urilend == NULL) {
SCLogDebug("DetectUrilenSetup SCMalloc failed");
if (urilend == NULL)
goto error;
}
urilend->urilen1 = 0;
urilend->urilen2 = 0;

@ -139,10 +139,8 @@ DetectWindowData *DetectWindowParse(char *windowstr) {
}
wd = SCMalloc(sizeof(DetectWindowData));
if (wd == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "malloc failed");
if (wd == NULL)
goto error;
}
if (ret > 1) {

@ -238,6 +238,8 @@ char *DetectLoadCompleteSigPath(char *sig_file)
size_t path_len = sizeof(char) * (strlen(defaultpath) +
strlen(sig_file) + 2);
path = SCMalloc(path_len);
if (path == NULL)
return NULL;
strlcpy(path, defaultpath, path_len);
if (path[strlen(path) - 1] != '/')
strlcat(path, "/", path_len);

@ -36,7 +36,7 @@
FlowQueue *FlowQueueNew() {
FlowQueue *q = (FlowQueue *)SCMalloc(sizeof(FlowQueue));
if (q == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,"Error allocating flow queue");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in FlowQueueNew. Exiting...");
exit(EXIT_SUCCESS);
}
q = FlowQueueInit(q);

@ -526,8 +526,8 @@ void FlowInitConfig (char quiet)
/* alloc hash memory */
flow_hash = SCCalloc(flow_config.hash_size, sizeof(FlowBucket));
if (flow_hash == NULL) {
printf("SCCalloc failed %s\n", strerror(errno));
exit(1);
SCLogError(SC_ERR_FATAL, "Fatal error encountered in FlowInitConfig. Exiting...");
exit(EXIT_FAILURE);
}
uint32_t i = 0;

@ -350,9 +350,8 @@ TmEcode LogHttpLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
TmEcode LogHttpLogThreadInit(ThreadVars *t, void *initdata, void **data)
{
LogHttpLogThread *aft = SCMalloc(sizeof(LogHttpLogThread));
if (aft == NULL) {
if (aft == NULL)
return TM_ECODE_FAILED;
}
memset(aft, 0, sizeof(LogHttpLogThread));
if(initdata == NULL)
@ -418,11 +417,8 @@ OutputCtx *LogHttpLogInitCtx(ConfNode *conf)
return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate OutputCtx for LogHttpLog");
exit(EXIT_FAILURE);
}
if (output_ctx == NULL)
return NULL;
output_ctx->data = file_ctx;
output_ctx->DeInit = LogHttpLogDeInitCtx;

@ -48,8 +48,7 @@ OutputRegisterModule(char *name, char *conf_name,
{
OutputModule *module = SCCalloc(1, sizeof(*module));
if (module == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocated memory for new output module");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in OutputRegisterModule. Exiting...");
exit(EXIT_FAILURE);
}

@ -78,7 +78,6 @@ void PktVarAdd(Packet *p, char *name, uint8_t *value, uint16_t size) {
tpv->next = pv;
return;
}
tpv = tpv->next;
}
}

@ -45,10 +45,8 @@ IPReputationCtx *rep_ctx;
*/
IPReputationCtx *SCReputationInitCtx() {
rep_ctx = (IPReputationCtx *)SCMalloc(sizeof(IPReputationCtx));
if (rep_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for Reputation context");
exit(EXIT_FAILURE);
}
if (rep_ctx == NULL)
return NULL;
memset(rep_ctx,0,sizeof(IPReputationCtx));
rep_ctx->reputationIPV4_tree = SCRadixCreateRadixTree(SCReputationFreeData, NULL);
@ -89,10 +87,8 @@ Reputation *SCReputationAllocData()
{
Reputation *rep_data = NULL;
if ( (rep_data = SCMalloc(sizeof(Reputation))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (rep_data = SCMalloc(sizeof(Reputation))) == NULL)
return NULL;
memset(rep_data,0, sizeof(Reputation));
rep_data->ctime = time(NULL);
rep_data->mtime= time(NULL);
@ -122,10 +118,8 @@ ReputationTransaction *SCReputationTransactionAlloc()
{
ReputationTransaction *rtx = NULL;
if ( (rtx = SCMalloc(sizeof(ReputationTransaction))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (rtx = SCMalloc(sizeof(ReputationTransaction))) == NULL)
return NULL;
memset(rtx, 0, sizeof(ReputationTransaction));
return rtx;
@ -230,10 +224,8 @@ Reputation *SCReputationClone(Reputation *orig)
return NULL;
}
if ( (rep = SCMalloc(sizeof(Reputation))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (rep = SCMalloc(sizeof(Reputation))) == NULL)
return NULL;
memcpy(rep, orig, sizeof(Reputation));
return rep;
}

@ -121,11 +121,8 @@ void RunModeInitializeOutputs(void)
exit(EXIT_FAILURE);
}
RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
if (runmode_output == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate memory for output.");
exit(EXIT_FAILURE);
}
if (runmode_output == NULL)
return;
runmode_output->tm_module = tm_module;
runmode_output->output_ctx = output_ctx;
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);

@ -316,10 +316,8 @@ TmEcode ReceiveIPFWThreadInit(ThreadVars *tv, void *initdata, void **data) {
/* Setup Threadvars */
IPFWThreadVars *ptv = SCMalloc(sizeof(IPFWThreadVars));
if (ptv == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,"Error Allocating memory for IPFW Receive PTV: %s",strerror(errno));
if (ptv == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(ptv, 0, sizeof(IPFWThreadVars));
SCMutexInit(&ipfw_socket_lock, NULL);
@ -452,10 +450,8 @@ TmEcode DecodeIPFWThreadInit(ThreadVars *tv, void *initdata, void **data)
{
DecodeThreadVars *dtv = NULL;
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,"Error Allocating memory for IPFW Decode DTV: %s",strerror(errno));
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(dtv, 0, sizeof(DecodeThreadVars));
DecodeRegisterPerfCounters(dtv, tv);
@ -601,10 +597,8 @@ TmEcode VerdictIPFWThreadInit(ThreadVars *tv, void *initdata, void **data) {
SCEnter();
/* Setup Thread vars */
if ( (ptv = SCMalloc(sizeof(IPFWThreadVars))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,"Error Allocating memory for IPFW Verdict PTV: %s", strerror(errno));
if ( (ptv = SCMalloc(sizeof(IPFWThreadVars))) == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(ptv, 0, sizeof(IPFWThreadVars));

@ -498,6 +498,7 @@ process_rv:
* \brief NFQ receive module main entry function: receive a packet from NFQ
*/
TmEcode ReceiveNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
NFQThreadVars *ntv = (NFQThreadVars *)data;
/* make sure we have at least one packet in the packet pool, to prevent
@ -572,6 +573,7 @@ void NFQSetVerdict(NFQThreadVars *t, Packet *p) {
* \brief NFQ verdict module packet entry function
*/
TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
NFQThreadVars *ntv = (NFQThreadVars *)data;
/* if this is a tunnel packet we check if we are ready to verdict
@ -609,6 +611,7 @@ TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
*/
TmEcode DecodeNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
IPV4Hdr *ip4h = (IPV4Hdr *)p->pkt;
IPV6Hdr *ip6h = (IPV6Hdr *)p->pkt;
DecodeThreadVars *dtv = (DecodeThreadVars *)data;
@ -642,10 +645,8 @@ TmEcode DecodeNFQThreadInit(ThreadVars *tv, void *initdata, void **data)
{
DecodeThreadVars *dtv = NULL;
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed");
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL)
return TM_ECODE_FAILED;
}
memset(dtv, 0, sizeof(DecodeThreadVars));
DecodeRegisterPerfCounters(dtv, tv);

@ -162,10 +162,8 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, void *initdata, void **data) {
SCLogInfo("reading pcap file %s", (char *)initdata);
PcapFileThreadVars *ptv = SCMalloc(sizeof(PcapFileThreadVars));
if (ptv == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for PcapFileThreadVars");
if (ptv == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(ptv, 0, sizeof(PcapFileThreadVars));
char errbuf[PCAP_ERRBUF_SIZE] = "";
@ -264,10 +262,8 @@ TmEcode DecodePcapFileThreadInit(ThreadVars *tv, void *initdata, void **data)
SCEnter();
DecodeThreadVars *dtv = NULL;
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error Allocating memory for DecodeThreadVars");
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(dtv, 0, sizeof(DecodeThreadVars));
DecodeRegisterPerfCounters(dtv, tv);

@ -195,10 +195,8 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) {
}
PcapThreadVars *ptv = SCMalloc(sizeof(PcapThreadVars));
if (ptv == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Couldn't allocate PcapThreadVars");
if (ptv == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(ptv, 0, sizeof(PcapThreadVars));
ptv->tv = tv;
@ -284,10 +282,8 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) {
}
PcapThreadVars *ptv = SCMalloc(sizeof(PcapThreadVars));
if (ptv == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Couldn't allocate PcapThreadVars");
if (ptv == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(ptv, 0, sizeof(PcapThreadVars));
ptv->tv = tv;
@ -424,10 +420,8 @@ TmEcode DecodePcapThreadInit(ThreadVars *tv, void *initdata, void **data)
SCEnter();
DecodeThreadVars *dtv = NULL;
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error Allocating memory");
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(dtv, 0, sizeof(DecodeThreadVars));
DecodeRegisterPerfCounters(dtv, tv);

@ -241,9 +241,8 @@ TmEcode ReceivePfringThreadInit(ThreadVars *tv, void *initdata, void **data) {
char *tmpctype;
PfringThreadVars *ptv = SCMalloc(sizeof(PfringThreadVars));
if (ptv == NULL) {
if (ptv == NULL)
return TM_ECODE_FAILED;
}
memset(ptv, 0, sizeof(PfringThreadVars));
ptv->tv = tv;
@ -386,10 +385,8 @@ TmEcode DecodePfringThreadInit(ThreadVars *tv, void *initdata, void **data)
{
DecodeThreadVars *dtv = NULL;
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,"Error Allocating memory");
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL)
return TM_ECODE_FAILED;
}
memset(dtv, 0, sizeof(DecodeThreadVars));
DecodeRegisterPerfCounters(dtv, tv);

@ -222,9 +222,8 @@ TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(void)
{
SCEnter();
TcpReassemblyThreadCtx *ra_ctx = SCMalloc(sizeof(TcpReassemblyThreadCtx));
if (ra_ctx == NULL) {
if (ra_ctx == NULL)
return NULL;
}
memset(ra_ctx, 0x00, sizeof(TcpReassemblyThreadCtx));
ra_ctx->stream_q = StreamMsgQueueGetNew();

@ -2578,9 +2578,8 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
{
SCEnter();
StreamTcpThread *stt = SCMalloc(sizeof(StreamTcpThread));
if (stt == NULL) {
if (stt == NULL)
SCReturnInt(TM_ECODE_FAILED);
}
memset(stt, 0, sizeof(StreamTcpThread));
*data = (void *)stt;
@ -4075,10 +4074,8 @@ char *StreamTcpParseOSPolicy (char *conf_var_name)
/* the + 2 is for the '.' and the string termination character '\0' */
conf_var_full_name = (char *)SCMalloc(strlen(conf_var_type_name) +
strlen(conf_var_name) + 2);
if (conf_var_full_name == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
if (conf_var_full_name == NULL)
goto end;
}
if (snprintf(conf_var_full_name,
strlen(conf_var_type_name) + strlen(conf_var_name) + 2, "%s.%s",

@ -182,9 +182,8 @@ void StreamMsgQueuesDeinit(char quiet) {
* \retval smq ptr to the queue or NULL */
StreamMsgQueue *StreamMsgQueueGetNew(void) {
StreamMsgQueue *smq = SCMalloc(sizeof(StreamMsgQueue));
if (smq == NULL) {
if (smq == NULL)
return NULL;
}
memset(smq, 0x00, sizeof(StreamMsgQueue));
SCMutexInit(&smq->mutex_q, NULL);

@ -243,10 +243,8 @@ static void SetBpfString(int optind, char *argv[]) {
return;
bpf_filter = SCMalloc(bpf_len);
if (bpf_filter == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "%s", strerror(errno));
exit(EXIT_FAILURE);
}
if (bpf_filter == NULL)
return;
memset(bpf_filter, 0x00, bpf_len);
tmpindex = optind;
@ -803,7 +801,7 @@ int main(int argc, char **argv)
/* XXX pkt alloc function */
Packet *p = SCMalloc(sizeof(Packet));
if (p == NULL) {
printf("ERROR: SCMalloc failed: %s\n", strerror(errno));
SCLogError(SC_ERR_FATAL, "Fatal error encountered while allocating a packet. Exiting...");
exit(EXIT_FAILURE);
}
PACKET_INITIALIZE(p);

@ -72,10 +72,7 @@ LogFileCtx *LogFileNewCtx()
lf_ctx=(LogFileCtx*)SCMalloc(sizeof(LogFileCtx));
if(lf_ctx == NULL)
{
SCLogError(SC_ERR_MEM_ALLOC, "Couldn't SCMalloc");
return NULL;
}
memset(lf_ctx, 0, sizeof(LogFileCtx));
SCMutexInit(&lf_ctx->fp_mutex,NULL);

@ -585,7 +585,8 @@ TmEcode TmThreadSetSlots(ThreadVars *tv, char *name, void *(*fn_p)(void *)) {
}
tv->tm_slots = SCMalloc(size);
if (tv->tm_slots == NULL) goto error;
if (tv->tm_slots == NULL)
goto error;
memset(tv->tm_slots, 0, size);
return TM_ECODE_OK;
@ -765,7 +766,8 @@ ThreadVars *TmThreadCreate(char *name, char *inq_name, char *inqh_name,
/* XXX create separate function for this: allocate a thread container */
tv = SCMalloc(sizeof(ThreadVars));
if (tv == NULL) goto error;
if (tv == NULL)
goto error;
memset(tv, 0, sizeof(ThreadVars));
SCSpinInit(&tv->flags_spinlock, PTHREAD_PROCESS_PRIVATE);
@ -1153,8 +1155,8 @@ void TmThreadSetAOF(ThreadVars *tv, uint8_t aof)
void TmThreadInitMC(ThreadVars *tv)
{
if ( (tv->m = SCMalloc(sizeof(SCMutex))) == NULL) {
printf("Error allocating memory\n");
exit(0);
SCLogError(SC_ERR_FATAL, "Fatal error encountered in TmThreadInitMC. Exiting...");
exit(EXIT_FAILURE);
}
if (SCMutexInit(tv->m, NULL) != 0) {
@ -1163,7 +1165,7 @@ void TmThreadInitMC(ThreadVars *tv)
}
if ( (tv->cond = SCMalloc(sizeof(SCCondT))) == NULL) {
printf("Error allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in TmThreadInitMC. Exiting...");
exit(0);
}

@ -105,6 +105,9 @@ static int StoreQueueId(TmqhFlowCtx *ctx, char *name) {
} else {
ctx->size++;
ctx->queues = SCRealloc(ctx->queues, ctx->size * sizeof(uint16_t));
if (ctx->queues == NULL) {
return -1;
}
}
if (ctx->queues == NULL) {
return -1;

@ -343,10 +343,8 @@ SCClassConfClasstype *SCClassConfAllocClasstype(const char *classtype,
if (classtype == NULL)
return NULL;
if ( (ct = SCMalloc(sizeof(SCClassConfClasstype))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (ct = SCMalloc(sizeof(SCClassConfClasstype))) == NULL)
return NULL;
memset(ct, 0, sizeof(SCClassConfClasstype));
if ( (ct->classtype = SCClassConfStringToLowercase(classtype)) == NULL) {

@ -326,14 +326,12 @@ int SCCudaHlGetCudaDevicePtr(CUdeviceptr *device_ptr, const char *name,
}
new_module_device_ptr = SCMalloc(sizeof(SCCudaHlModuleDevicePointer));
if (new_module_device_ptr == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if (new_module_device_ptr == NULL)
goto error;
memset(new_module_device_ptr, 0, sizeof(SCCudaHlModuleDevicePointer));
if ( (new_module_device_ptr->name = SCStrdup(name)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCCudaHlGetCudaDevicePtr. Exiting...");
exit(EXIT_FAILURE);
}
@ -479,7 +477,7 @@ int SCCudaHlRegisterModule(const char *name)
/* the module is not already registered. Register the module */
new_data = SCMalloc(sizeof(SCCudaHlModuleData));
if (new_data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCCudaHlRegisterModule. Exiting...");
exit(EXIT_FAILURE);
}
memset(new_data, 0, sizeof(SCCudaHlModuleData));
@ -714,7 +712,7 @@ void SCCudaHlProcessUriWithDispatcher(uint8_t *uri, uint16_t uri_len,
Packet *p = SCMalloc(sizeof(Packet));
if (p == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCCudaHlProcessUriWithDispatcher. Exiting...");
exit(EXIT_FAILURE);
}
memset(p, 0, sizeof(Packet));

@ -3614,10 +3614,8 @@ static int SCCudaDeviceGetAttribute(int *pi, CUdevice_attribute attrib,
static SCCudaDevice *SCCudaAllocSCCudaDevice(void)
{
SCCudaDevice *device = SCMalloc(sizeof(SCCudaDevice));
if (device == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if (device == NULL)
return NULL;
memset(device, 0 , sizeof(SCCudaDevice));
return device;
@ -3645,10 +3643,8 @@ static void SCCudaDeAllocSCCudaDevice(SCCudaDevice *device)
static SCCudaDevices *SCCudaAllocSCCudaDevices(void)
{
SCCudaDevices *devices = SCMalloc(sizeof(SCCudaDevices));
if (devices == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if (devices == NULL)
return NULL;
memset(devices, 0 , sizeof(SCCudaDevices));
return devices;
@ -3696,10 +3692,8 @@ static SCCudaDevices *SCCudaGetDevices(void)
goto error;
devices->devices = SCMalloc(devices->count * sizeof(SCCudaDevice *));
if (devices->devices == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if (devices->devices == NULL)
goto error;
/* update the device properties */
for (i = 0; i < devices->count; i++) {

@ -591,10 +591,8 @@ int SCLogCheckFDFilterEntry(const char *function)
return 1;
}
if ( (thread_list_temp = SCMalloc(sizeof(SCLogFDFilterThreadList))) == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
}
if ( (thread_list_temp = SCMalloc(sizeof(SCLogFDFilterThreadList))) == NULL)
return 0;
memset(thread_list_temp, 0, sizeof(SCLogFDFilterThreadList));
thread_list_temp->t = self;
@ -707,10 +705,8 @@ int SCLogAddFDFilter(const char *function)
curr = curr->next;
}
if ( (temp = SCMalloc(sizeof(SCLogFDFilter))) == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
}
if ( (temp = SCMalloc(sizeof(SCLogFDFilter))) == NULL)
return -1;
memset(temp, 0, sizeof(SCLogFDFilter));
if ( (temp->func = SCStrdup(function)) == NULL) {
@ -876,7 +872,7 @@ void SCLogAddToFGFFileList(SCLogFGFilterFile *fgf_file,
SCLogFGFilterLine *fgf_line_temp = NULL;
if ( (fgf_file_temp = SCMalloc(sizeof(SCLogFGFilterFile))) == NULL) {
printf("Error Allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAddToFGFFileList. Exiting...");
exit(EXIT_FAILURE);
}
memset(fgf_file_temp, 0, sizeof(SCLogFGFilterFile));
@ -887,7 +883,7 @@ void SCLogAddToFGFFileList(SCLogFGFilterFile *fgf_file,
}
if ( (fgf_func_temp = SCMalloc(sizeof(SCLogFGFilterFunc))) == NULL) {
printf("Error Allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAddToFGFFileList. Exiting...");
exit(EXIT_FAILURE);
}
memset(fgf_func_temp, 0, sizeof(SCLogFGFilterFunc));
@ -898,7 +894,7 @@ void SCLogAddToFGFFileList(SCLogFGFilterFile *fgf_file,
}
if ( (fgf_line_temp = SCMalloc(sizeof(SCLogFGFilterLine))) == NULL) {
printf("Error Allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAddToFGFFileList. Exiting...");
exit(EXIT_FAILURE);
}
memset(fgf_line_temp, 0, sizeof(SCLogFGFilterLine));
@ -940,7 +936,7 @@ void SCLogAddToFGFFuncList(SCLogFGFilterFile *fgf_file,
SCLogFGFilterLine *fgf_line_temp = NULL;
if ( (fgf_func_temp = SCMalloc(sizeof(SCLogFGFilterFunc))) == NULL) {
printf("Error Allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAddToFGFFuncList. Exiting...");
exit(EXIT_FAILURE);
}
memset(fgf_func_temp, 0, sizeof(SCLogFGFilterFunc));
@ -951,7 +947,7 @@ void SCLogAddToFGFFuncList(SCLogFGFilterFile *fgf_file,
}
if ( (fgf_line_temp = SCMalloc(sizeof(SCLogFGFilterLine))) == NULL) {
printf("Error Allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAddToFGFFuncList. Exiting...");
exit(EXIT_FAILURE);
}
memset(fgf_line_temp, 0, sizeof(SCLogFGFilterLine));
@ -989,7 +985,7 @@ void SCLogAddToFGFLineList(SCLogFGFilterFunc *fgf_func,
SCLogFGFilterLine *fgf_line_temp = NULL;
if ( (fgf_line_temp = SCMalloc(sizeof(SCLogFGFilterLine))) == NULL) {
printf("Error Allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAddToFGFLineList. Exiting...");
exit(EXIT_FAILURE);
}
memset(fgf_line_temp, 0, sizeof(SCLogFGFilterLine));

@ -485,9 +485,9 @@ SCLogOPBuffer *SCLogAllocLogOPBuffer(void)
SCLogOPIfaceCtx *op_iface_ctx = NULL;
int i = 0;
if ( (buffer = malloc(sc_log_config->op_ifaces_cnt *
if ( (buffer = SCMalloc(sc_log_config->op_ifaces_cnt *
sizeof(SCLogOPBuffer))) == NULL) {
printf("Error allocating memory\n");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAllocLogOPBuffer. Exiting...");
exit(EXIT_FAILURE);
}
@ -513,8 +513,8 @@ static inline SCLogOPIfaceCtx *SCLogAllocLogOPIfaceCtx()
{
SCLogOPIfaceCtx *iface_ctx = NULL;
if ( (iface_ctx = malloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
printf("Error allocating memory\n");
if ( (iface_ctx = SCMalloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogallocLogOPIfaceCtx. Exiting...");
exit(EXIT_FAILURE);
}
memset(iface_ctx, 0, sizeof(SCLogOPIfaceCtx));
@ -577,8 +577,8 @@ static inline SCLogOPIfaceCtx *SCLogInitConsoleOPIface(const char *log_format,
{
SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx();
if ( (iface_ctx = malloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
printf("Error allocating memory\n");
if ( (iface_ctx = SCMalloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitConsoleOPIface. Exiting...");
exit(EXIT_FAILURE);
}
memset(iface_ctx, 0, sizeof(SCLogOPIfaceCtx));
@ -632,8 +632,8 @@ static inline SCLogOPIfaceCtx *SCLogInitSyslogOPIface(int facility,
{
SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx();
if ( (iface_ctx = malloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
printf("Error allocating memory\n");
if ( (iface_ctx = SCMalloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitSyslogOPIface. Exiting...");
exit(EXIT_FAILURE);
}
memset(iface_ctx, 0, sizeof(SCLogOPIfaceCtx));
@ -905,10 +905,8 @@ SCLogInitData *SCLogAllocLogInitData(void)
{
SCLogInitData *sc_lid = NULL;
if ( (sc_lid = malloc(sizeof(SCLogInitData))) == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
}
if ( (sc_lid = SCMalloc(sizeof(SCLogInitData))) == NULL)
return NULL;
memset(sc_lid, 0, sizeof(SCLogInitData));
return sc_lid;
@ -1050,8 +1048,8 @@ void SCLogInitLogModule(SCLogInitData *sc_lid)
SCLogDeInitLogModule();
/* sc_log_config is a global variable */
if ( (sc_log_config = malloc(sizeof(SCLogConfig))) == NULL) {
printf("Error Allocating memory\n");
if ( (sc_log_config = SCMalloc(sizeof(SCLogConfig))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitLogModule. Exiting...");
exit(EXIT_FAILURE);
}
memset(sc_log_config, 0, sizeof(SCLogConfig));
@ -1081,6 +1079,10 @@ void SCLogLoadConfig(void)
}
sc_lid = SCLogAllocLogInitData();
if (sc_lid == NULL) {
SCLogDebug("Could not allocate memory for log init data");
return;
}
/* Get default log level and format. */
char *default_log_level_s = NULL;
@ -1190,10 +1192,8 @@ void SCLogInitLogModuleIfEnvSet(void)
SCLogLevel log_level = SC_LOG_NOTSET;
/* sc_log_config is a global variable */
if ( (sc_log_config = malloc(sizeof(SCLogConfig))) == NULL) {
printf("Error Allocating memory\n");
exit(EXIT_FAILURE);
}
if ( (sc_log_config = SCMalloc(sizeof(SCLogConfig))) == NULL)
return;
memset(sc_log_config, 0, sizeof(SCLogConfig));
sc_lc = sc_log_config;
@ -1318,7 +1318,7 @@ static char *SCLogGetLogFilename(char *filearg)
if (ConfGet("default-log-dir", &log_dir) != 1)
log_dir = DEFAULT_LOG_DIR;
log_filename = malloc(PATH_MAX);
log_filename = SCMalloc(PATH_MAX);
if (log_filename == NULL)
return NULL;
snprintf(log_filename, PATH_MAX, "%s/%s", log_dir, filearg);
@ -1408,6 +1408,8 @@ int SCLogTestInit02()
int result = 1;
char *logfile = SCLogGetLogFilename("boo.txt");
sc_lid = SCLogAllocLogInitData();
if (sc_lid == NULL)
return 0;
sc_lid->startup_message = "Test02";
sc_lid->global_log_level = SC_LOG_DEBUG;
sc_lid->op_filter = "boo";
@ -1441,6 +1443,8 @@ int SCLogTestInit02()
SCLogDeInitLogModule();
sc_lid = SCLogAllocLogInitData();
if (sc_lid == NULL)
return 0;
sc_lid->startup_message = "Test02";
sc_lid->global_log_level = SC_LOG_DEBUG;
sc_lid->op_filter = "boo";

@ -184,6 +184,7 @@ typedef enum {
SC_ERR_CHANGING_CAPS_FAILED,
SC_ERR_LIBCAP_NG_REQUIRED,
SC_ERR_LIBNET11_INCOMPATIBLE_WITH_LIBCAP_NG,
SC_ERR_FATAL,
} SCError;

@ -166,6 +166,8 @@ static int CloseFn(void *handler) {
*/
FILE *SCFmemopen(void *buf, size_t size, const char *mode) {
SCFmem *mem = (SCFmem *) SCMalloc(sizeof(SCFmem));
if (mem == NULL)
return NULL;
memset(mem, 0, sizeof(SCFmem));
mem->size = size, mem->buffer = buf;

@ -114,9 +114,8 @@ int HashTableAdd(HashTable *ht, void *data, uint16_t datalen) {
uint32_t hash = ht->Hash(ht, data, datalen);
HashTableBucket *hb = SCMalloc(sizeof(HashTableBucket));
if (hb == NULL) {
if (hb == NULL)
goto error;
}
memset(hb, 0, sizeof(HashTableBucket));
hb->data = data;
hb->size = datalen;

@ -119,9 +119,8 @@ int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen) {
SCLogDebug("ht %p hash %"PRIu32"", ht, hash);
HashListTableBucket *hb = SCMalloc(sizeof(HashListTableBucket));
if (hb == NULL) {
if (hb == NULL)
goto error;
}
memset(hb, 0, sizeof(HashListTableBucket));
hb->data = data;
hb->size = datalen;

@ -76,7 +76,7 @@ static struct in_addr *SCHInfoValidateIPV4Address(const char *addr_str)
struct in_addr *addr = NULL;
if ( (addr = SCMalloc(sizeof(struct in_addr))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCHInfoValidateIPV4Address. Exiting...");
exit(EXIT_FAILURE);
}
@ -103,7 +103,7 @@ static struct in6_addr *SCHInfoValidateIPV6Address(const char *addr_str)
struct in6_addr *addr = NULL;
if ( (addr = SCMalloc(sizeof(struct in6_addr))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCHInfoValidateIPV6Address. Exiting...");
exit(EXIT_FAILURE);
}
@ -129,10 +129,8 @@ static void *SCHInfoAllocUserDataOSPolicy(const char *host_os)
{
int *user_data = NULL;
if ( (user_data = SCMalloc(sizeof(int))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (user_data = SCMalloc(sizeof(int))) == NULL)
return NULL;
/* the host os flavour that has to be sent as user data */
if ( (*user_data = SCMapEnumNameToValue(host_os, sc_hinfo_os_policy_map)) == -1) {

@ -34,12 +34,10 @@
* It will log a lot of lines more, so think that is a performance killer */
/* Uncomment this if you want to print memory allocations and free's() */
//#define DBG_MEM_ALLOC
#define DBG_MEM_ALLOC
/* Uncomment this if you want to print mallocs at the startup (recommended) */
//#define DBG_MEM_ALLOC_SKIP_STARTUP
#ifdef DBG_MEM_ALLOC
#define DBG_MEM_ALLOC_SKIP_STARTUP
#define SCMalloc(a) ({ \
void *ptrmem = NULL; \
@ -47,8 +45,7 @@
extern uint8_t print_mem_flag; \
ptrmem = malloc(a); \
if (ptrmem == NULL && a > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "Malloc of size %"PRIu64" failed! exiting.", (uint64_t)a); \
exit(EXIT_FAILURE); \
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s, while trying to allocate %"PRIu64" bytes", strerror(errno), (uint64_t)a); \
} \
global_mem += a; \
if (print_mem_flag == 1) \
@ -62,8 +59,7 @@
extern uint8_t print_mem_flag; \
ptrmem = realloc(x, a); \
if (ptrmem == NULL && a > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "Realloc of size %"PRIu64" failed! exiting.", (uint64_t)a); \
exit(EXIT_FAILURE); \
SCLogError(SC_ERR_MEM_ALLOC, "SCRealloc failed: %s, while trying to allocate %"PRIu64" bytes", strerror(errno), (uint64_t)a); \
} \
global_mem += a; \
if (print_mem_flag == 1) \
@ -77,8 +73,7 @@
extern uint8_t print_mem_flag; \
ptrmem = calloc(nm, a); \
if (ptrmem == NULL && a > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "Calloc of size %"PRIu64" failed! exiting.", (uint64_t)a); \
exit(EXIT_FAILURE); \
SCLogError(SC_ERR_MEM_ALLOC, "SCCalloc failed: %s, while trying to allocate %"PRIu64" bytes", strerror(errno), (uint64_t)a); \
} \
global_mem += a*nm; \
if (print_mem_flag == 1) \
@ -109,16 +104,6 @@
free(a); \
})
#else
/* Replace them with the normal calls, so we get no performance penalty */
#define SCMalloc(a) malloc(a)
#define SCCalloc(nm,a) calloc(nm,a)
#define SCRealloc(x,a) realloc(x,a)
#define SCStrdup(a) strdup(a)
#define SCFree(a) free(a)
#endif
//#endif /* __UTIL_MEM_H__ */

@ -552,10 +552,8 @@ void B2gCudaPrintInfo(MpmCtx *mpm_ctx)
static inline B2gCudaPattern *B2gCudaAllocPattern(MpmCtx *mpm_ctx)
{
B2gCudaPattern *p = SCMalloc(sizeof(B2gCudaPattern));
if (p == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if (p == NULL)
return NULL;
memset(p, 0, sizeof(B2gCudaPattern));
mpm_ctx->memory_cnt++;
@ -567,10 +565,8 @@ static inline B2gCudaPattern *B2gCudaAllocPattern(MpmCtx *mpm_ctx)
static inline B2gCudaHashItem *B2gCudaAllocHashItem(MpmCtx *mpm_ctx)
{
B2gCudaHashItem *hi = SCMalloc(sizeof(B2gCudaHashItem));
if (hi == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if (hi == NULL)
return NULL;
memset(hi, 0, sizeof(B2gCudaHashItem));
mpm_ctx->memory_cnt++;
@ -861,6 +857,8 @@ static void B2gCudaPrepareHash(MpmCtx *mpm_ctx)
ctx->hash1[idx8].flags |= 0x01;
} else {
B2gCudaHashItem *hi = B2gCudaAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -876,12 +874,16 @@ static void B2gCudaPrepareHash(MpmCtx *mpm_ctx)
idx = B2G_CUDA_HASH16(ctx->parray[i]->ci[0], ctx->parray[i]->ci[1]);
if (ctx->hash2[idx] == NULL) {
B2gCudaHashItem *hi = B2gCudaAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
ctx->hash2[idx] = hi;
} else {
B2gCudaHashItem *hi = B2gCudaAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -901,6 +903,8 @@ static void B2gCudaPrepareHash(MpmCtx *mpm_ctx)
if (ctx->hash[idx] == NULL) {
B2gCudaHashItem *hi = B2gCudaAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
ctx->pminlen[idx] = ctx->parray[i]->len;
@ -908,6 +912,8 @@ static void B2gCudaPrepareHash(MpmCtx *mpm_ctx)
ctx->hash[idx] = hi;
} else {
B2gCudaHashItem *hi = B2gCudaAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;

@ -125,10 +125,8 @@ void B2gPrintInfo(MpmCtx *mpm_ctx) {
static inline B2gPattern *B2gAllocPattern(MpmCtx *mpm_ctx) {
B2gPattern *p = SCMalloc(sizeof(B2gPattern));
if (p == NULL) {
printf("ERROR: B2gAllocPattern: SCMalloc failed\n");
exit(EXIT_FAILURE);
}
if (p == NULL)
return NULL;
memset(p,0,sizeof(B2gPattern));
mpm_ctx->memory_cnt++;
@ -139,10 +137,8 @@ static inline B2gPattern *B2gAllocPattern(MpmCtx *mpm_ctx) {
static inline B2gHashItem *
B2gAllocHashItem(MpmCtx *mpm_ctx) {
B2gHashItem *hi = SCMalloc(sizeof(B2gHashItem));
if (hi == NULL) {
printf("ERROR: B2gAllocHashItem: SCMalloc failed\n");
exit(EXIT_FAILURE);
}
if (hi == NULL)
return NULL;
memset(hi,0,sizeof(B2gHashItem));
mpm_ctx->memory_cnt++;
@ -390,7 +386,8 @@ static void B2gPrepareHash(MpmCtx *mpm_ctx) {
uint8_t idx8 = 0;
ctx->hash = (B2gHashItem **)SCMalloc(sizeof(B2gHashItem *) * ctx->hash_size);
if (ctx->hash == NULL) goto error;
if (ctx->hash == NULL)
goto error;
memset(ctx->hash, 0, sizeof(B2gHashItem *) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -398,7 +395,8 @@ static void B2gPrepareHash(MpmCtx *mpm_ctx) {
#ifdef B2G_SEARCH2
ctx->hash2 = (B2gHashItem **)SCMalloc(sizeof(B2gHashItem *) * ctx->hash_size);
if (ctx->hash2 == NULL) goto error;
if (ctx->hash2 == NULL)
goto error;
memset(ctx->hash2, 0, sizeof(B2gHashItem *) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -407,7 +405,8 @@ static void B2gPrepareHash(MpmCtx *mpm_ctx) {
/* alloc the pminlen array */
ctx->pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->hash_size);
if (ctx->pminlen == NULL) goto error;
if (ctx->pminlen == NULL)
goto error;
memset(ctx->pminlen, 0, sizeof(uint8_t) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -422,6 +421,8 @@ static void B2gPrepareHash(MpmCtx *mpm_ctx) {
ctx->hash1[idx8].flags |= 0x01;
} else {
B2gHashItem *hi = B2gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -436,12 +437,16 @@ static void B2gPrepareHash(MpmCtx *mpm_ctx) {
idx = B2G_HASH16(ctx->parray[i]->ci[0],ctx->parray[i]->ci[1]);
if (ctx->hash2[idx] == NULL) {
B2gHashItem *hi = B2gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
ctx->hash2[idx] = hi;
} else {
B2gHashItem *hi = B2gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -458,6 +463,8 @@ static void B2gPrepareHash(MpmCtx *mpm_ctx) {
if (ctx->hash[idx] == NULL) {
B2gHashItem *hi = B2gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
ctx->pminlen[idx] = ctx->parray[i]->len;
@ -465,6 +472,8 @@ static void B2gPrepareHash(MpmCtx *mpm_ctx) {
ctx->hash[idx] = hi;
} else {
B2gHashItem *hi = B2gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -482,7 +491,8 @@ static void B2gPrepareHash(MpmCtx *mpm_ctx) {
/* alloc the bloom array */
ctx->bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->hash_size);
if (ctx->bloom == NULL) goto error;
if (ctx->bloom == NULL)
goto error;
memset(ctx->bloom, 0, sizeof(BloomFilter *) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -555,7 +565,8 @@ int B2gPreparePatterns(MpmCtx *mpm_ctx) {
/* alloc the pattern array */
ctx->parray = (B2gPattern **)SCMalloc(mpm_ctx->pattern_cnt * sizeof(B2gPattern *));
if (ctx->parray == NULL) goto error;
if (ctx->parray == NULL)
goto error;
memset(ctx->parray, 0, mpm_ctx->pattern_cnt * sizeof(B2gPattern *));
//printf("mpm_ctx %p, parray %p\n", mpm_ctx,ctx->parray);
mpm_ctx->memory_cnt++;

@ -119,10 +119,8 @@ void B3gPrintInfo(MpmCtx *mpm_ctx) {
static inline B3gPattern *B3gAllocPattern(MpmCtx *mpm_ctx) {
B3gPattern *p = SCMalloc(sizeof(B3gPattern));
if (p == NULL) {
printf("ERROR: B3gAllocPattern: SCMalloc failed\n");
exit(EXIT_FAILURE);
}
if (p == NULL)
return NULL;
memset(p,0,sizeof(B3gPattern));
mpm_ctx->memory_cnt++;
@ -133,10 +131,8 @@ static inline B3gPattern *B3gAllocPattern(MpmCtx *mpm_ctx) {
static inline B3gHashItem *
B3gAllocHashItem(MpmCtx *mpm_ctx) {
B3gHashItem *hi = SCMalloc(sizeof(B3gHashItem));
if (hi == NULL) {
printf("ERROR: B3gAllocHashItem: SCMalloc failed\n");
exit(EXIT_FAILURE);
}
if (hi == NULL)
return NULL;
memset(hi,0,sizeof(B3gHashItem));
mpm_ctx->memory_cnt++;
@ -379,7 +375,8 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
uint8_t idx8 = 0;
ctx->hash = (B3gHashItem **)SCMalloc(sizeof(B3gHashItem *) * ctx->hash_size);
if (ctx->hash == NULL) goto error;
if (ctx->hash == NULL)
goto error;
memset(ctx->hash, 0, sizeof(B3gHashItem *) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -387,7 +384,8 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
/* 2 byte pattern hash */
ctx->hash2 = (B3gHashItem **)SCMalloc(sizeof(B3gHashItem *) * ctx->hash_size);
if (ctx->hash2 == NULL) goto error;
if (ctx->hash2 == NULL)
goto error;
memset(ctx->hash2, 0, sizeof(B3gHashItem *) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -395,7 +393,8 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
/* alloc the pminlen array */
ctx->pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->hash_size);
if (ctx->pminlen == NULL) goto error;
if (ctx->pminlen == NULL)
goto error;
memset(ctx->pminlen, 0, sizeof(uint8_t) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -410,6 +409,8 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
ctx->hash1[idx8].flags |= 0x01;
} else {
B3gHashItem *hi = B3gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -423,12 +424,16 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
idx = (uint16_t)(ctx->parray[i]->ci[0] << B3G_HASHSHIFT | ctx->parray[i]->ci[1]);
if (ctx->hash2[idx] == NULL) {
B3gHashItem *hi = B3gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
ctx->hash2[idx] = hi;
} else {
B3gHashItem *hi = B3gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -444,6 +449,8 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
if (ctx->hash[idx] == NULL) {
B3gHashItem *hi = B3gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
ctx->pminlen[idx] = ctx->parray[i]->len;
@ -451,6 +458,8 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
ctx->hash[idx] = hi;
} else {
B3gHashItem *hi = B3gAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -468,7 +477,8 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
/* alloc the bloom array */
ctx->bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->hash_size);
if (ctx->bloom == NULL) goto error;
if (ctx->bloom == NULL)
goto error;
memset(ctx->bloom, 0, sizeof(BloomFilter *) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -538,7 +548,8 @@ int B3gPreparePatterns(MpmCtx *mpm_ctx) {
/* alloc the pattern array */
ctx->parray = (B3gPattern **)SCMalloc(mpm_ctx->pattern_cnt * sizeof(B3gPattern *));
if (ctx->parray == NULL) goto error;
if (ctx->parray == NULL)
goto error;
memset(ctx->parray, 0, mpm_ctx->pattern_cnt * sizeof(B3gPattern *));
//printf("mpm_ctx %p, parray %p\n", mpm_ctx,ctx->parray);
mpm_ctx->memory_cnt++;

@ -163,10 +163,8 @@ void WmPrintInfo(MpmCtx *mpm_ctx) {
static inline WmPattern *WmAllocPattern(MpmCtx *mpm_ctx) {
WmPattern *p = SCMalloc(sizeof(WmPattern));
if (p == NULL) {
printf("ERROR: WmAllocPattern: SCMalloc failed\n");
exit(EXIT_FAILURE);
}
if (p == NULL)
return NULL;
memset(p,0,sizeof(WmPattern));
mpm_ctx->memory_cnt++;
@ -177,10 +175,8 @@ static inline WmPattern *WmAllocPattern(MpmCtx *mpm_ctx) {
static inline WmHashItem *
WmAllocHashItem(MpmCtx *mpm_ctx) {
WmHashItem *hi = SCMalloc(sizeof(WmHashItem));
if (hi == NULL) {
printf("ERROR: WmAllocHashItem: SCMalloc failed\n");
exit(EXIT_FAILURE);
}
if (hi == NULL)
return NULL;
memset(hi,0,sizeof(WmHashItem));
mpm_ctx->memory_cnt++;
@ -447,7 +443,8 @@ static void WmSearchPrepareHash(MpmCtx *mpm_ctx) {
uint8_t idx8 = 0;
ctx->hash = (WmHashItem **)SCMalloc(sizeof(WmHashItem *) * ctx->hash_size);
if (ctx->hash == NULL) goto error;
if (ctx->hash == NULL)
goto error;
memset(ctx->hash, 0, sizeof(WmHashItem *) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -455,7 +452,8 @@ static void WmSearchPrepareHash(MpmCtx *mpm_ctx) {
/* alloc the pminlen array */
ctx->pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->hash_size);
if (ctx->pminlen == NULL) goto error;
if (ctx->pminlen == NULL)
goto error;
memset(ctx->pminlen, 0, sizeof(uint8_t) * ctx->hash_size);
for (i = 0; i < mpm_ctx->pattern_cnt; i++)
@ -467,6 +465,8 @@ static void WmSearchPrepareHash(MpmCtx *mpm_ctx) {
ctx->hash1[idx8].flags |= 0x01;
} else {
WmHashItem *hi = WmAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -491,6 +491,8 @@ static void WmSearchPrepareHash(MpmCtx *mpm_ctx) {
if (ctx->hash[idx] == NULL) {
WmHashItem *hi = WmAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
ctx->pminlen[idx] = ctx->parray[i]->len;
@ -498,6 +500,8 @@ static void WmSearchPrepareHash(MpmCtx *mpm_ctx) {
ctx->hash[idx] = hi;
} else {
WmHashItem *hi = WmAllocHashItem(mpm_ctx);
if (hi == NULL)
goto error;
hi->idx = i;
hi->flags |= 0x01;
@ -514,7 +518,8 @@ static void WmSearchPrepareHash(MpmCtx *mpm_ctx) {
/* alloc the bloom array */
ctx->bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->hash_size);
if (ctx->bloom == NULL) goto error;
if (ctx->bloom == NULL)
goto error;
memset(ctx->bloom, 0, sizeof(BloomFilter *) * ctx->hash_size);
mpm_ctx->memory_cnt++;
@ -638,7 +643,8 @@ int WmPreparePatterns(MpmCtx *mpm_ctx) {
/* alloc the pattern array */
ctx->parray = (WmPattern **)SCMalloc(mpm_ctx->pattern_cnt * sizeof(WmPattern *));
if (ctx->parray == NULL) goto error;
if (ctx->parray == NULL)
goto error;
memset(ctx->parray, 0, mpm_ctx->pattern_cnt * sizeof(WmPattern *));
//printf("mpm_ctx %p, parray %p\n", mpm_ctx,ctx->parray);
mpm_ctx->memory_cnt++;
@ -1329,7 +1335,6 @@ void WmInitCtx (MpmCtx *mpm_ctx, int module_handle) {
mpm_ctx->ctx = SCMalloc(sizeof(WmCtx));
if (mpm_ctx->ctx == NULL)
return;
memset(mpm_ctx->ctx, 0, sizeof(WmCtx));
mpm_ctx->memory_cnt++;

@ -57,7 +57,6 @@ int PmqSetup(PatternMatcherQueue *pmq, uint32_t sig_maxid, uint32_t patmaxid) {
if (patmaxid > 0) {
pmq->pattern_id_array = SCMalloc(patmaxid * sizeof(uint32_t));
if (pmq->pattern_id_array == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "memory alloc failed");
SCReturnInt(-1);
}
memset(pmq->pattern_id_array, 0, patmaxid * sizeof(uint32_t));
@ -66,7 +65,6 @@ int PmqSetup(PatternMatcherQueue *pmq, uint32_t sig_maxid, uint32_t patmaxid) {
/* lookup bitarray */
pmq->pattern_id_bitarray = SCMalloc((patmaxid / 8) + 1);
if (pmq->pattern_id_bitarray == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "memory alloc failed");
SCReturnInt(-1);
}
memset(pmq->pattern_id_bitarray, 0, (patmaxid / 8) + 1);

@ -218,7 +218,8 @@ void *PoolTestAlloc(void *allocdata) {
void *PoolTestAllocArg(void *allocdata) {
size_t len = strlen((char *)allocdata) + 1;
char *str = SCMalloc(len);
strlcpy(str,(char *)allocdata,len);
if (str != NULL)
strlcpy(str,(char *)allocdata,len);
return (void *)str;
}

@ -59,7 +59,7 @@ struct in_addr *SCRadixValidateIPV4Address(const char *addr_str)
struct in_addr *addr = NULL;
if ( (addr = SCMalloc(sizeof(struct in_addr))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixValidateIPV4Address. Exiting...");
exit(EXIT_FAILURE);
}
@ -86,7 +86,7 @@ struct in6_addr *SCRadixValidateIPV6Address(const char *addr_str)
struct in6_addr *addr = NULL;
if ( (addr = SCMalloc(sizeof(struct in6_addr))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixValidateIPV6Address. Exiting...");
exit(EXIT_FAILURE);
}
@ -141,9 +141,10 @@ static SCRadixUserData *SCRadixAllocSCRadixUserData(uint8_t netmask, void *user)
{
SCRadixUserData *user_data = SCMalloc(sizeof(SCRadixUserData));
if (user_data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixAllocSCRadixUserData. Exiting...");
exit(EXIT_FAILURE);
}
memset(user_data, 0, sizeof(SCRadixUserData));
user_data->netmask = netmask;
@ -236,16 +237,12 @@ static SCRadixPrefix *SCRadixCreatePrefix(uint8_t *key_stream,
return NULL;
}
if ( (prefix = SCMalloc(sizeof(SCRadixPrefix))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (prefix = SCMalloc(sizeof(SCRadixPrefix))) == NULL)
return NULL;
memset(prefix, 0, sizeof(SCRadixPrefix));
if ( (prefix->stream = SCMalloc(key_bitlen / 8)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
if ( (prefix->stream = SCMalloc(key_bitlen / 8)) == NULL)
return NULL;
memset(prefix->stream, 0, key_bitlen / 8);
memcpy(prefix->stream, key_stream, key_bitlen / 8);
@ -462,7 +459,7 @@ static inline SCRadixNode *SCRadixCreateNode()
SCRadixNode *node = NULL;
if ( (node = SCMalloc(sizeof(SCRadixNode))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixCreateNode. Exiting...");
exit(EXIT_FAILURE);
}
memset(node, 0, sizeof(SCRadixNode));
@ -499,7 +496,7 @@ SCRadixTree *SCRadixCreateRadixTree(void (*Free)(void*), void (*PrintData)(void*
SCRadixTree *tree = NULL;
if ( (tree = SCMalloc(sizeof(SCRadixTree))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixCreateRadixTree. Exiting...");
exit(EXIT_FAILURE);
}
memset(tree, 0, sizeof(SCRadixTree));
@ -613,7 +610,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen,
node->netmask_cnt++;
if ( (node->netmasks = SCRealloc(node->netmasks, (node->netmask_cnt *
sizeof(uint8_t)))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixAddKey. Exiting...");
exit(EXIT_FAILURE);
}
node->netmasks[0] = netmask;
@ -731,7 +728,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen,
node->netmask_cnt++;
if ( (node->netmasks = SCRealloc(node->netmasks, (node->netmask_cnt *
sizeof(uint8_t)))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixAddKey. Exiting...");
exit(EXIT_FAILURE);
}
@ -803,7 +800,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen,
if ( (inter_node->netmasks = SCMalloc((node->netmask_cnt - i) *
sizeof(uint8_t))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixAddKey. Exiting...");
exit(EXIT_FAILURE);
}
@ -851,7 +848,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen,
node->netmask_cnt++;
if ( (node->netmasks = SCRealloc(node->netmasks, (node->netmask_cnt *
sizeof(uint8_t)))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCRadixAddKey. Exiting...");
exit(EXIT_FAILURE);
}
@ -1084,10 +1081,8 @@ static void SCRadixTransferNetmasksBWNodes(SCRadixNode *dest, SCRadixNode *src)
if ( (dest->netmasks = SCRealloc(dest->netmasks,
(src->netmask_cnt + dest->netmask_cnt) *
sizeof(uint8_t))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
sizeof(uint8_t))) == NULL)
return;
for (i = dest->netmask_cnt, j = 0; j < src->netmask_cnt; i++, j++)
dest->netmasks[i] = src->netmasks[j];
@ -1149,10 +1144,8 @@ static void SCRadixRemoveNetblockEntry(SCRadixNode *node, uint8_t netmask)
}
node->netmasks = SCRealloc(node->netmasks, node->netmask_cnt * sizeof(uint8_t));
if (node->netmasks == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory using realloc");
exit(EXIT_FAILURE);
}
if (node->netmasks == NULL)
return;
return;
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save