Use unlikely in malloc failure test.

This patch is a result of applying the following coccinelle
transformation to suricata sources:

  @istested@
  identifier x;
  statement S1;
  identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)";
  @@

  x = func(...)
  ... when != x
  - if (x == NULL) S1
  + if (unlikely(x == NULL)) S1
pull/604/head
Eric Leblond 13 years ago
parent c8b3f4418a
commit 79fcf1378a

@ -129,7 +129,7 @@ void DNSSetEvent(DNSState *s, uint8_t e) {
* \retval tx or NULL */ * \retval tx or NULL */
DNSTransaction *DNSTransactionAlloc(const uint16_t tx_id) { DNSTransaction *DNSTransactionAlloc(const uint16_t tx_id) {
DNSTransaction *tx = SCMalloc(sizeof(DNSTransaction)); DNSTransaction *tx = SCMalloc(sizeof(DNSTransaction));
if (tx == NULL) if (unlikely(tx == NULL))
return NULL; return NULL;
memset(tx, 0x00, sizeof(DNSTransaction)); memset(tx, 0x00, sizeof(DNSTransaction));
@ -329,7 +329,7 @@ void DNSStoreQueryInState(DNSState *dns_state, const uint8_t *fqdn, const uint16
} }
DNSQueryEntry *q = SCMalloc(sizeof(DNSQueryEntry) + fqdn_len); DNSQueryEntry *q = SCMalloc(sizeof(DNSQueryEntry) + fqdn_len);
if (q == NULL) if (unlikely(q == NULL))
return; return;
q->type = type; q->type = type;
q->class = class; q->class = class;
@ -357,7 +357,7 @@ void DNSStoreAnswerInState(DNSState *dns_state, const int rtype, const uint8_t *
} }
DNSAnswerEntry *q = SCMalloc(sizeof(DNSAnswerEntry) + fqdn_len + data_len); DNSAnswerEntry *q = SCMalloc(sizeof(DNSAnswerEntry) + fqdn_len + data_len);
if (q == NULL) if (unlikely(q == NULL))
return; return;
q->type = type; q->type = type;
q->class = class; q->class = class;

@ -2002,7 +2002,7 @@ static int HTPCallbackRequestLine(htp_tx_t *tx)
return HTP_OK; return HTP_OK;
tx_ud = SCMalloc(sizeof(*tx_ud)); tx_ud = SCMalloc(sizeof(*tx_ud));
if (tx_ud == NULL) { if (unlikely(tx_ud == NULL)) {
bstr_free(request_uri_normalized); bstr_free(request_uri_normalized);
return HTP_OK; return HTP_OK;
} }
@ -2047,7 +2047,7 @@ static int HTPCallbackRequestHeaderData(htp_tx_data_t *tx_data)
HtpTxUserData *tx_ud = htp_tx_get_user_data(tx_data->tx); HtpTxUserData *tx_ud = htp_tx_get_user_data(tx_data->tx);
if (tx_ud == NULL) { if (tx_ud == NULL) {
tx_ud = SCMalloc(sizeof(*tx_ud)); tx_ud = SCMalloc(sizeof(*tx_ud));
if (tx_ud == NULL) if (unlikely(tx_ud == NULL))
return HTP_OK; return HTP_OK;
memset(tx_ud, 0, sizeof(*tx_ud)); memset(tx_ud, 0, sizeof(*tx_ud));
htp_tx_set_user_data(tx_data->tx, tx_ud); htp_tx_set_user_data(tx_data->tx, tx_ud);
@ -2079,7 +2079,7 @@ static int HTPCallbackResponseHeaderData(htp_tx_data_t *tx_data)
HtpTxUserData *tx_ud = htp_tx_get_user_data(tx_data->tx); HtpTxUserData *tx_ud = htp_tx_get_user_data(tx_data->tx);
if (tx_ud == NULL) { if (tx_ud == NULL) {
tx_ud = SCMalloc(sizeof(*tx_ud)); tx_ud = SCMalloc(sizeof(*tx_ud));
if (tx_ud == NULL) if (unlikely(tx_ud == NULL))
return HTP_OK; return HTP_OK;
memset(tx_ud, 0, sizeof(*tx_ud)); memset(tx_ud, 0, sizeof(*tx_ud));
htp_tx_set_user_data(tx_data->tx, tx_ud); htp_tx_set_user_data(tx_data->tx, tx_ud);
@ -4966,7 +4966,7 @@ libhtp:\n\
HTPConfigure(); HTPConfigure();
httpbuf = SCMalloc(len); httpbuf = SCMalloc(len);
if (httpbuf == NULL) if (unlikely(httpbuf == NULL))
goto end; goto end;
memset(httpbuf, 0x00, len); memset(httpbuf, 0x00, len);

@ -1777,7 +1777,7 @@ static uint32_t AppLayerProbingParserGetMask(uint16_t al_proto)
static inline AppLayerProbingParserElement *AllocAppLayerProbingParserElement(void) static inline AppLayerProbingParserElement *AllocAppLayerProbingParserElement(void)
{ {
AppLayerProbingParserElement *p = SCMalloc(sizeof(AppLayerProbingParserElement)); AppLayerProbingParserElement *p = SCMalloc(sizeof(AppLayerProbingParserElement));
if (p == NULL) { if (unlikely(p == NULL)) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(p, 0, sizeof(AppLayerProbingParserElement)); memset(p, 0, sizeof(AppLayerProbingParserElement));
@ -1796,7 +1796,7 @@ static inline void DeAllocAppLayerProbingParserElement(AppLayerProbingParserElem
static inline AppLayerProbingParserPort *AllocAppLayerProbingParserPort(void) static inline AppLayerProbingParserPort *AllocAppLayerProbingParserPort(void)
{ {
AppLayerProbingParserPort *p = SCMalloc(sizeof(AppLayerProbingParserPort)); AppLayerProbingParserPort *p = SCMalloc(sizeof(AppLayerProbingParserPort));
if (p == NULL) { if (unlikely(p == NULL)) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(p, 0, sizeof(AppLayerProbingParserPort)); memset(p, 0, sizeof(AppLayerProbingParserPort));
@ -1830,7 +1830,7 @@ static inline void DeAllocAppLayerProbingParserPort(AppLayerProbingParserPort *p
static inline AppLayerProbingParser *AllocAppLayerProbingParser(void) static inline AppLayerProbingParser *AllocAppLayerProbingParser(void)
{ {
AppLayerProbingParser *p = SCMalloc(sizeof(AppLayerProbingParser)); AppLayerProbingParser *p = SCMalloc(sizeof(AppLayerProbingParser));
if (p == NULL) { if (unlikely(p == NULL)) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(p, 0, sizeof(AppLayerProbingParser)); memset(p, 0, sizeof(AppLayerProbingParser));

@ -2079,7 +2079,7 @@ int DetectContentParseTest41(void)
DetectContentData *cd = NULL; DetectContentData *cd = NULL;
int patlen = 257; int patlen = 257;
char *teststring = SCMalloc(sizeof(char) * (patlen + 1)); char *teststring = SCMalloc(sizeof(char) * (patlen + 1));
if (teststring == NULL) if (unlikely(teststring == NULL))
return 0; return 0;
int idx = 0; int idx = 0;
teststring[idx++] = '\"'; teststring[idx++] = '\"';
@ -2106,7 +2106,7 @@ int DetectContentParseTest42(void)
DetectContentData *cd = NULL; DetectContentData *cd = NULL;
int patlen = 258; int patlen = 258;
char *teststring = SCMalloc(sizeof(char) * (patlen + 1)); char *teststring = SCMalloc(sizeof(char) * (patlen + 1));
if (teststring == NULL) if (unlikely(teststring == NULL))
return 0; return 0;
int idx = 0; int idx = 0;
teststring[idx++] = '\"'; teststring[idx++] = '\"';
@ -2133,7 +2133,7 @@ int DetectContentParseTest43(void)
DetectContentData *cd = NULL; DetectContentData *cd = NULL;
int patlen = 260; int patlen = 260;
char *teststring = SCMalloc(sizeof(char) * (patlen + 1)); char *teststring = SCMalloc(sizeof(char) * (patlen + 1));
if (teststring == NULL) if (unlikely(teststring == NULL))
return 0; return 0;
int idx = 0; int idx = 0;
teststring[idx++] = '\"'; teststring[idx++] = '\"';
@ -2164,7 +2164,7 @@ int DetectContentParseTest44(void)
DetectContentData *cd = NULL; DetectContentData *cd = NULL;
int patlen = 261; int patlen = 261;
char *teststring = SCMalloc(sizeof(char) * (patlen + 1)); char *teststring = SCMalloc(sizeof(char) * (patlen + 1));
if (teststring == NULL) if (unlikely(teststring == NULL))
return 0; return 0;
int idx = 0; int idx = 0;
teststring[idx++] = '\"'; teststring[idx++] = '\"';

@ -3502,7 +3502,7 @@ static int DetectEngineHttpClientBodyTest29(void)
#define TOTAL_REQUESTS 45 #define TOTAL_REQUESTS 45
uint8_t *http_buf = SCMalloc(TOTAL_REQUESTS * strlen(request_buffer)); uint8_t *http_buf = SCMalloc(TOTAL_REQUESTS * strlen(request_buffer));
if (http_buf == NULL) if (unlikely(http_buf == NULL))
goto end; goto end;
for (int i = 0; i < TOTAL_REQUESTS; i++) { for (int i = 0; i < TOTAL_REQUESTS; i++) {
memcpy(http_buf + i * strlen(request_buffer), request_buffer, memcpy(http_buf + i * strlen(request_buffer), request_buffer,

@ -157,7 +157,7 @@ static uint8_t *DetectEngineHHDGetBufferForTX(htp_tx_t *tx, uint64_t tx_id,
/* the extra 4 bytes if for ": " and "\r\n" */ /* the extra 4 bytes if for ": " and "\r\n" */
headers_buffer = SCRealloc(headers_buffer, headers_buffer_len + size1 + size2 + 4); headers_buffer = SCRealloc(headers_buffer, headers_buffer_len + size1 + size2 + 4);
if (headers_buffer == NULL) { if (unlikely(headers_buffer == NULL)) {
det_ctx->hhd_buffers[index] = NULL; det_ctx->hhd_buffers[index] = NULL;
det_ctx->hhd_buffers_len[index] = 0; det_ctx->hhd_buffers_len[index] = 0;
goto end; goto end;

@ -2838,7 +2838,7 @@ int DetectSetFastPatternAndItsId(DetectEngineCtx *de_ctx)
/* array hash buffer - i've run out of ideas to name it */ /* array hash buffer - i've run out of ideas to name it */
uint8_t *ahb = SCMalloc(sizeof(uint8_t) * (struct_total_size + content_total_size)); uint8_t *ahb = SCMalloc(sizeof(uint8_t) * (struct_total_size + content_total_size));
if (ahb == NULL) if (unlikely(ahb == NULL))
return -1; return -1;
uint8_t *content = NULL; uint8_t *content = NULL;

@ -250,7 +250,7 @@ int LuajitSetFlowvar(lua_State *luastate) {
} }
buffer = SCMalloc(len+1); buffer = SCMalloc(len+1);
if (buffer == NULL) { if (unlikely(buffer == NULL)) {
lua_pushnil(luastate); lua_pushnil(luastate);
lua_pushstring(luastate, "out of memory"); lua_pushstring(luastate, "out of memory");
return 2; return 2;

@ -174,7 +174,7 @@ static int FlowStorageTest02(void) {
} }
void *ptr1a = SCMalloc(128); void *ptr1a = SCMalloc(128);
if (ptr1a == NULL) { if (unlikely(ptr1a == NULL)) {
goto error; goto error;
} }
FlowSetStorageById(f, id1, ptr1a); FlowSetStorageById(f, id1, ptr1a);
@ -230,13 +230,13 @@ static int FlowStorageTest03(void) {
} }
void *ptr1a = SCMalloc(128); void *ptr1a = SCMalloc(128);
if (ptr1a == NULL) { if (unlikely(ptr1a == NULL)) {
goto error; goto error;
} }
FlowSetStorageById(f, id1, ptr1a); FlowSetStorageById(f, id1, ptr1a);
void *ptr2a = SCMalloc(256); void *ptr2a = SCMalloc(256);
if (ptr2a == NULL) { if (unlikely(ptr2a == NULL)) {
goto error; goto error;
} }
FlowSetStorageById(f, id2, ptr2a); FlowSetStorageById(f, id2, ptr2a);

@ -173,7 +173,7 @@ static int HostStorageTest02(void) {
} }
void *ptr1a = SCMalloc(128); void *ptr1a = SCMalloc(128);
if (ptr1a == NULL) { if (unlikely(ptr1a == NULL)) {
goto error; goto error;
} }
HostSetStorageById(h, id1, ptr1a); HostSetStorageById(h, id1, ptr1a);
@ -228,13 +228,13 @@ static int HostStorageTest03(void) {
} }
void *ptr1a = SCMalloc(128); void *ptr1a = SCMalloc(128);
if (ptr1a == NULL) { if (unlikely(ptr1a == NULL)) {
goto error; goto error;
} }
HostSetStorageById(h, id1, ptr1a); HostSetStorageById(h, id1, ptr1a);
void *ptr2a = SCMalloc(256); void *ptr2a = SCMalloc(256);
if (ptr2a == NULL) { if (unlikely(ptr2a == NULL)) {
goto error; goto error;
} }
HostSetStorageById(h, id2, ptr2a); HostSetStorageById(h, id2, ptr2a);

@ -81,7 +81,7 @@ void *ParseMpipeConfig(const char *iface)
char *copymodestr; char *copymodestr;
char *out_iface = NULL; char *out_iface = NULL;
if (aconf == NULL) { if (unlikely(aconf == NULL)) {
return NULL; return NULL;
} }
@ -202,14 +202,14 @@ int RunModeTileMpipeWorkers(DetectEngineCtx *de_ctx)
} else { } else {
mpipe_devc = SCStrdup(mpipe_dev); mpipe_devc = SCStrdup(mpipe_dev);
} }
if (mpipe_devc == NULL) { if (unlikely(mpipe_devc == NULL)) {
printf("ERROR: SCStrdup failed for ReceiveMpipe\n"); printf("ERROR: SCStrdup failed for ReceiveMpipe\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
snprintf(tname, sizeof(tname), "Worker%d", pipe+1); snprintf(tname, sizeof(tname), "Worker%d", pipe+1);
thread_name = SCStrdup(tname); thread_name = SCStrdup(tname);
if (thread_name == NULL) { if (unlikely(thread_name == NULL)) {
printf("ERROR: SCStrdup failed for ReceiveMpipe\n"); printf("ERROR: SCStrdup failed for ReceiveMpipe\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

@ -787,7 +787,7 @@ TmEcode ReceiveMpipeThreadInit(ThreadVars *tv, void *initdata, void **data)
} }
MpipeThreadVars *ptv = SCMalloc(sizeof(MpipeThreadVars)); MpipeThreadVars *ptv = SCMalloc(sizeof(MpipeThreadVars));
if (ptv == NULL) if (unlikely(ptv == NULL))
SCReturnInt(TM_ECODE_FAILED); SCReturnInt(TM_ECODE_FAILED);
memset(ptv, 0, sizeof(MpipeThreadVars)); memset(ptv, 0, sizeof(MpipeThreadVars));
@ -863,7 +863,7 @@ TmEcode ReceiveMpipeThreadInit(ThreadVars *tv, void *initdata, void **data)
/* Allocate some ingress queues. */ /* Allocate some ingress queues. */
iqueues = SCCalloc(num_workers, sizeof(*iqueues)); iqueues = SCCalloc(num_workers, sizeof(*iqueues));
if (iqueues == NULL) if (unlikely(iqueues == NULL))
SCReturnInt(TM_ECODE_FAILED); SCReturnInt(TM_ECODE_FAILED);
/* Allocate some NotifRings. */ /* Allocate some NotifRings. */
@ -984,7 +984,7 @@ TmEcode DecodeMpipe(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq,
int MpipeLiveRegisterDevice(char *dev) int MpipeLiveRegisterDevice(char *dev)
{ {
MpipeDevice *nd = SCMalloc(sizeof(MpipeDevice)); MpipeDevice *nd = SCMalloc(sizeof(MpipeDevice));
if (nd == NULL) { if (unlikely(nd == NULL)) {
return -1; return -1;
} }

@ -156,9 +156,8 @@ TmEcode NapatechStreamThreadInit(ThreadVars *tv, void *initdata, void **data)
SCLogInfo("Napatech Thread Stream ID:%lu", stream_id); SCLogInfo("Napatech Thread Stream ID:%lu", stream_id);
NapatechThreadVars *ntv = SCMalloc(sizeof(NapatechThreadVars)); NapatechThreadVars *ntv = SCMalloc(sizeof(NapatechThreadVars));
if (ntv == NULL) { if (unlikely(ntv == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for NAPATECH thread vars.");
"Failed to allocate memory for NAPATECH thread vars.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

@ -1054,7 +1054,7 @@ int StreamTcp3whsQueueSynAck(TcpSession *ssn, Packet *p) {
} }
TcpStateQueue *q = SCMalloc(sizeof(*q)); TcpStateQueue *q = SCMalloc(sizeof(*q));
if (q == NULL) { if (unlikely(q == NULL)) {
SCLogDebug("ssn %p: =~ SYN/ACK queue failed: alloc failed", ssn); SCLogDebug("ssn %p: =~ SYN/ACK queue failed: alloc failed", ssn);
return -1; return -1;
} }

@ -382,7 +382,7 @@ CudaBufferData *CudaBufferRegisterNew(uint8_t *d_buffer, uint32_t d_buffer_len,
} }
CudaBufferData *new = SCMalloc(sizeof(CudaBufferData)); CudaBufferData *new = SCMalloc(sizeof(CudaBufferData));
if (new == NULL) { if (unlikely(new == NULL)) {
return NULL; return NULL;
} }
memset(new, 0, sizeof(CudaBufferData)); memset(new, 0, sizeof(CudaBufferData));
@ -406,7 +406,7 @@ CudaBufferData *CudaBufferRegisterNew(uint8_t *d_buffer, uint32_t d_buffer_len,
static void *CudaBufferSlicePoolAlloc(void *null) static void *CudaBufferSlicePoolAlloc(void *null)
{ {
void *ptr = SCMalloc(sizeof(CudaBufferSlice)); void *ptr = SCMalloc(sizeof(CudaBufferSlice));
if (ptr == NULL) if (unlikely(ptr == NULL))
return NULL; return NULL;
memset(ptr, 0, sizeof(CudaBufferSlice)); memset(ptr, 0, sizeof(CudaBufferSlice));

@ -83,7 +83,7 @@ void CudaHandlerAddCudaProfileFromConf(const char *name,
} }
CudaHandlerConfProfile *new_cp = SCMalloc(sizeof(CudaHandlerConfProfile)); CudaHandlerConfProfile *new_cp = SCMalloc(sizeof(CudaHandlerConfProfile));
if (new_cp == NULL) if (unlikely(new_cp == NULL))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
memset(new_cp, 0, sizeof(CudaHandlerConfProfile)); memset(new_cp, 0, sizeof(CudaHandlerConfProfile));
new_cp->name = SCStrdup(name); new_cp->name = SCStrdup(name);
@ -188,7 +188,7 @@ CUcontext CudaHandlerModuleGetContext(const char *name, int device_id)
} }
CudaHandlerModule *new_module = SCMalloc(sizeof(CudaHandlerModule)); CudaHandlerModule *new_module = SCMalloc(sizeof(CudaHandlerModule));
if (new_module == NULL) if (unlikely(new_module == NULL))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
memset(new_module, 0, sizeof(CudaHandlerModule)); memset(new_module, 0, sizeof(CudaHandlerModule));
new_module->device_id = device_id; new_module->device_id = device_id;
@ -204,7 +204,7 @@ CUcontext CudaHandlerModuleGetContext(const char *name, int device_id)
if (no_of_cuda_contexts <= device_id) { if (no_of_cuda_contexts <= device_id) {
cuda_contexts = SCRealloc(cuda_contexts, sizeof(CUcontext) * (device_id + 1)); cuda_contexts = SCRealloc(cuda_contexts, sizeof(CUcontext) * (device_id + 1));
if (cuda_contexts == NULL) if (unlikely(cuda_contexts == NULL))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
memset(cuda_contexts + no_of_cuda_contexts, 0, memset(cuda_contexts + no_of_cuda_contexts, 0,
sizeof(CUcontext) * ((device_id + 1) - no_of_cuda_contexts)); sizeof(CUcontext) * ((device_id + 1) - no_of_cuda_contexts));
@ -253,7 +253,7 @@ void CudaHandlerModuleStoreData(const char *module_name,
} }
CudaHandlerModuleData *new_data = SCMalloc(sizeof(CudaHandlerModuleData)); CudaHandlerModuleData *new_data = SCMalloc(sizeof(CudaHandlerModuleData));
if (new_data == NULL) if (unlikely(new_data == NULL))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
memset(new_data, 0, sizeof(CudaHandlerModuleData)); memset(new_data, 0, sizeof(CudaHandlerModuleData));
new_data->name = SCStrdup(data_name); new_data->name = SCStrdup(data_name);

@ -796,7 +796,7 @@ int SCCudaDeviceTotalMem(size_t *bytes, CUdevice dev)
static SCCudaDevice *SCCudaAllocSCCudaDevice(void) static SCCudaDevice *SCCudaAllocSCCudaDevice(void)
{ {
SCCudaDevice *device = SCMalloc(sizeof(SCCudaDevice)); SCCudaDevice *device = SCMalloc(sizeof(SCCudaDevice));
if (device == NULL) if (unlikely(device == NULL))
return NULL; return NULL;
memset(device, 0 , sizeof(SCCudaDevice)); memset(device, 0 , sizeof(SCCudaDevice));
@ -825,7 +825,7 @@ static void SCCudaDeAllocSCCudaDevice(SCCudaDevice *device)
static SCCudaDevices *SCCudaAllocSCCudaDevices(void) static SCCudaDevices *SCCudaAllocSCCudaDevices(void)
{ {
SCCudaDevices *devices = SCMalloc(sizeof(SCCudaDevices)); SCCudaDevices *devices = SCMalloc(sizeof(SCCudaDevices));
if (devices == NULL) if (unlikely(devices == NULL))
return NULL; return NULL;
memset(devices, 0 , sizeof(SCCudaDevices)); memset(devices, 0 , sizeof(SCCudaDevices));

@ -105,7 +105,7 @@ char *MagicGlobalLookup(uint8_t *buf, uint32_t buflen)
result = magic_buffer(g_magic_ctx, (void *)buf, (size_t)buflen); result = magic_buffer(g_magic_ctx, (void *)buf, (size_t)buflen);
if (result != NULL) { if (result != NULL) {
magic = SCStrdup(result); magic = SCStrdup(result);
if (magic == NULL) { if (unlikely(magic == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup magic"); SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup magic");
} }
} }
@ -132,7 +132,7 @@ char *MagicThreadLookup(magic_t *ctx, uint8_t *buf, uint32_t buflen)
result = magic_buffer(*ctx, (void *)buf, (size_t)buflen); result = magic_buffer(*ctx, (void *)buf, (size_t)buflen);
if (result != NULL) { if (result != NULL) {
magic = SCStrdup(result); magic = SCStrdup(result);
if (magic == NULL) { if (unlikely(magic == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup magic"); SCLogError(SC_ERR_MEM_ALLOC, "Unable to dup magic");
} }
} }

@ -826,7 +826,7 @@ static inline void SCACTileCreateDeltaTable(MpmCtx *mpm_ctx)
} }
int size = ctx->state_count * sizeof(SC_AC_TILE_STATE_TYPE_U16) * alpha_size; int size = ctx->state_count * sizeof(SC_AC_TILE_STATE_TYPE_U16) * alpha_size;
SC_AC_TILE_STATE_TYPE_U16 *state_table = SCMalloc(size); SC_AC_TILE_STATE_TYPE_U16 *state_table = SCMalloc(size);
if (state_table == NULL) { if (unlikely(state_table == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

@ -144,7 +144,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *nam
/* let's make the new entry */ /* let's make the new entry */
items = SCRealloc(items, items = SCRealloc(items,
(de_ctx->mpm_ctx_factory_container->no_of_items + 1) * sizeof(MpmCtxFactoryItem)); (de_ctx->mpm_ctx_factory_container->no_of_items + 1) * sizeof(MpmCtxFactoryItem));
if (items == NULL) { if (unlikely(items == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -283,7 +283,7 @@ static void *MpmCudaConfParse(ConfNode *node)
const char *value; const char *value;
MpmCudaConf *conf = SCMalloc(sizeof(MpmCudaConf)); MpmCudaConf *conf = SCMalloc(sizeof(MpmCudaConf));
if (conf == NULL) if (unlikely(conf == NULL))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
memset(conf, 0, sizeof(*conf)); memset(conf, 0, sizeof(*conf));

@ -46,7 +46,7 @@ PoolThread *PoolThreadInit(int threads, uint32_t size, uint32_t prealloc_size, u
} }
pt = SCMalloc(sizeof(*pt)); pt = SCMalloc(sizeof(*pt));
if (pt == NULL) { if (unlikely(pt == NULL)) {
SCLogDebug("memory alloc error"); SCLogDebug("memory alloc error");
goto error; goto error;
} }

@ -299,7 +299,7 @@ char *RunmodeAutoFpCreatePickupQueuesString(int n) {
char qname[TM_QUEUE_NAME_MAX]; char qname[TM_QUEUE_NAME_MAX];
queues = SCMalloc(queues_size); queues = SCMalloc(queues_size);
if (queues == NULL) { if (unlikely(queues == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, "failed to alloc queues buffer: %s", strerror(errno)); SCLogError(SC_ERR_MEM_ALLOC, "failed to alloc queues buffer: %s", strerror(errno));
return NULL; return NULL;
} }

@ -114,7 +114,7 @@ int StorageRegister(const StorageEnum type, const char *name, const unsigned int
} }
StorageList *entry = SCMalloc(sizeof(StorageList)); StorageList *entry = SCMalloc(sizeof(StorageList));
if (entry == NULL) if (unlikely(entry == NULL))
return -1; return -1;
memset(entry, 0x00, sizeof(StorageList)); memset(entry, 0x00, sizeof(StorageList));
@ -147,7 +147,7 @@ int StorageFinalize(void)
return 0; return 0;
storage_map = SCMalloc(sizeof(StorageMapping *) * STORAGE_MAX); storage_map = SCMalloc(sizeof(StorageMapping *) * STORAGE_MAX);
if (storage_map == NULL) { if (unlikely(storage_map == NULL)) {
return -1; return -1;
} }
memset(storage_map, 0x00, sizeof(StorageMapping *) * STORAGE_MAX); memset(storage_map, 0x00, sizeof(StorageMapping *) * STORAGE_MAX);
@ -258,7 +258,7 @@ void *StorageAllocById(Storage **storage, StorageEnum type, int id)
Storage *store = *storage; Storage *store = *storage;
if (store == NULL) { if (store == NULL) {
store = SCMalloc(sizeof(void *) * storage_max_id[type]); store = SCMalloc(sizeof(void *) * storage_max_id[type]);
if (store == NULL) if (unlikely(store == NULL))
return NULL; return NULL;
memset(store, 0x00, sizeof(void *) * storage_max_id[type]); memset(store, 0x00, sizeof(void *) * storage_max_id[type]);
} }

@ -1154,7 +1154,7 @@ void SCThresholdConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
else else
line = SCRealloc(line, strlen(line) + len + 1); line = SCRealloc(line, strlen(line) + len + 1);
if (line == NULL) { if (unlikely(line == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
break; break;
} }

Loading…
Cancel
Save