Replace all mallocs with SCMallocs

remotes/origin/master-1.1.x
Anoop Saldanha 14 years ago committed by Victor Julien
parent de59c9f4b1
commit 13ea299ee0

@ -676,7 +676,7 @@ static int DCERPCUDPParse(Flow *f, void *dcerpc_state,
} }
static void *DCERPCUDPStateAlloc(void) { static void *DCERPCUDPStateAlloc(void) {
void *s = malloc(sizeof(DCERPCUDPState)); void *s = SCMalloc(sizeof(DCERPCUDPState));
if (s == NULL) if (s == NULL)
return NULL; return NULL;

@ -434,7 +434,7 @@ void SCCudaPBDeAllocSCCudaPBPacketsBuffer(SCCudaPBPacketsBuffer *pb)
*/ */
SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void) SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void)
{ {
SCCudaPBPacketsBuffer *pb = malloc(sizeof(SCCudaPBPacketsBuffer)); SCCudaPBPacketsBuffer *pb = SCMalloc(sizeof(SCCudaPBPacketsBuffer));
if (pb == NULL) { if (pb == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -480,7 +480,7 @@ SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
pb->packets_buffer = malloc(profile->packet_buffer_limit * pb->packets_buffer = SCMalloc(profile->packet_buffer_limit *
(profile->packet_size_limit + (profile->packet_size_limit +
sizeof(SCCudaPBPacketDataForGPUNonPayload))); sizeof(SCCudaPBPacketDataForGPUNonPayload)));
if (pb->packets_buffer == NULL) { if (pb->packets_buffer == NULL) {
@ -501,7 +501,7 @@ SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
pb->packets_offset_buffer = malloc(sizeof(uint32_t) * pb->packets_offset_buffer = SCMalloc(sizeof(uint32_t) *
profile->packet_buffer_limit); profile->packet_buffer_limit);
if (pb->packets_offset_buffer == NULL) { if (pb->packets_offset_buffer == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
@ -521,7 +521,7 @@ SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
pb->packets_payload_offset_buffer = malloc(sizeof(uint32_t) * pb->packets_payload_offset_buffer = SCMalloc(sizeof(uint32_t) *
profile->packet_buffer_limit); profile->packet_buffer_limit);
if (pb->packets_payload_offset_buffer == NULL) { if (pb->packets_payload_offset_buffer == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
@ -538,7 +538,7 @@ SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void)
/* used to hold the packet addresses for all the packets buffered inside /* used to hold the packet addresses for all the packets buffered inside
* packets_buffer */ * packets_buffer */
pb->packets_address_buffer = malloc(sizeof(Packet *) * pb->packets_address_buffer = SCMalloc(sizeof(Packet *) *
profile->packet_buffer_limit); profile->packet_buffer_limit);
if (pb->packets_address_buffer == NULL) { if (pb->packets_address_buffer == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
@ -586,7 +586,7 @@ TmEcode SCCudaPBThreadInit(ThreadVars *tv, void *initdata, void **data)
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
tctx = malloc(sizeof(SCCudaPBThreadCtx)); tctx = SCMalloc(sizeof(SCCudaPBThreadCtx));
if (tctx == NULL) { if (tctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

@ -1159,7 +1159,7 @@ int DetectByteJumpTestPacket03(void)
int result = 0; int result = 0;
uint8_t *buf = NULL; uint8_t *buf = NULL;
uint16_t buflen = 0; uint16_t buflen = 0;
buf = malloc(4); buf = SCMalloc(4);
if (buf == NULL) { if (buf == NULL) {
printf("malloc failed\n"); printf("malloc failed\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

@ -1446,7 +1446,7 @@ int DetectByteTestTestPacket03(void)
int result = 0; int result = 0;
uint8_t *buf = NULL; uint8_t *buf = NULL;
uint16_t buflen = 0; uint16_t buflen = 0;
buf = malloc(4); buf = SCMalloc(4);
if (buf == NULL) { if (buf == NULL) {
printf("malloc failed\n"); printf("malloc failed\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

@ -68,7 +68,7 @@ static void SupportFastPatternForSigMatchList(int list_id)
} }
} }
SCFPSupportSMList *new_smlist_fp = malloc(sizeof(SCFPSupportSMList)); SCFPSupportSMList *new_smlist_fp = SCMalloc(sizeof(SCFPSupportSMList));
if (new_smlist_fp == NULL) { if (new_smlist_fp == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -100,7 +100,7 @@ static void SupportFastPatternForSigMatchType(uint8_t sm_type)
} }
} }
SCFPSupportSMType *new_smtype_fp = malloc(sizeof(SCFPSupportSMType)); SCFPSupportSMType *new_smtype_fp = SCMalloc(sizeof(SCFPSupportSMType));
if (new_smtype_fp == NULL) { if (new_smtype_fp == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

@ -117,7 +117,7 @@ void SCCudaHlGetYamlConf(void)
SCCudaHlCudaProfile *profile = NULL; SCCudaHlCudaProfile *profile = NULL;
/* "mpm" profile, found under "cuda.mpm" in the conf file */ /* "mpm" profile, found under "cuda.mpm" in the conf file */
profile = malloc(sizeof(SCCudaHlCudaProfile)); profile = SCMalloc(sizeof(SCCudaHlCudaProfile));
if (profile == NULL) { if (profile == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -469,7 +469,7 @@ int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle)
/* select the ptx image based on the compute capability supported by all /* select the ptx image based on the compute capability supported by all
* devices (i.e. the lowest) */ * devices (i.e. the lowest) */
char* image = malloc(strlen(ptx_image)+15); char* image = SCMalloc(strlen(ptx_image)+15);
memset(image, 0x0, sizeof(image)); memset(image, 0x0, sizeof(image));
int major = INT_MAX; int major = INT_MAX;

@ -492,7 +492,7 @@ SCLogOPBuffer *SCLogAllocLogOPBuffer(void)
SCLogOPIfaceCtx *op_iface_ctx = NULL; SCLogOPIfaceCtx *op_iface_ctx = NULL;
int i = 0; int i = 0;
if ( (buffer = malloc(sc_log_config->op_ifaces_cnt * if ( (buffer = SCMalloc(sc_log_config->op_ifaces_cnt *
sizeof(SCLogOPBuffer))) == NULL) { sizeof(SCLogOPBuffer))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAllocLogOPBuffer. Exiting..."); SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAllocLogOPBuffer. Exiting...");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -521,7 +521,7 @@ static inline SCLogOPIfaceCtx *SCLogAllocLogOPIfaceCtx()
{ {
SCLogOPIfaceCtx *iface_ctx = NULL; SCLogOPIfaceCtx *iface_ctx = NULL;
if ( (iface_ctx = malloc(sizeof(SCLogOPIfaceCtx))) == NULL) { if ( (iface_ctx = SCMalloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogallocLogOPIfaceCtx. Exiting..."); SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogallocLogOPIfaceCtx. Exiting...");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -935,7 +935,7 @@ SCLogInitData *SCLogAllocLogInitData(void)
SCLogInitData *sc_lid = NULL; SCLogInitData *sc_lid = NULL;
/* not using SCMalloc here because if it fails we can't log */ /* not using SCMalloc here because if it fails we can't log */
if ( (sc_lid = malloc(sizeof(SCLogInitData))) == NULL) if ( (sc_lid = SCMalloc(sizeof(SCLogInitData))) == NULL)
return NULL; return NULL;
memset(sc_lid, 0, sizeof(SCLogInitData)); memset(sc_lid, 0, sizeof(SCLogInitData));
@ -1086,7 +1086,7 @@ void SCLogInitLogModule(SCLogInitData *sc_lid)
#endif /* OS_WIN32 */ #endif /* OS_WIN32 */
/* sc_log_config is a global variable */ /* sc_log_config is a global variable */
if ( (sc_log_config = malloc(sizeof(SCLogConfig))) == NULL) { if ( (sc_log_config = SCMalloc(sizeof(SCLogConfig))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitLogModule. Exiting..."); SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitLogModule. Exiting...");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -1237,7 +1237,7 @@ void SCLogInitLogModuleIfEnvSet(void)
SCLogLevel log_level = SC_LOG_NOTSET; SCLogLevel log_level = SC_LOG_NOTSET;
/* sc_log_config is a global variable */ /* sc_log_config is a global variable */
if ( (sc_log_config = malloc(sizeof(SCLogConfig))) == NULL) if ( (sc_log_config = SCMalloc(sizeof(SCLogConfig))) == NULL)
return; return;
memset(sc_log_config, 0, sizeof(SCLogConfig)); memset(sc_log_config, 0, sizeof(SCLogConfig));
sc_lc = sc_log_config; sc_lc = sc_log_config;
@ -1363,7 +1363,7 @@ static char *SCLogGetLogFilename(char *filearg)
if (ConfGet("default-log-dir", &log_dir) != 1) if (ConfGet("default-log-dir", &log_dir) != 1)
log_dir = DEFAULT_LOG_DIR; log_dir = DEFAULT_LOG_DIR;
log_filename = malloc(PATH_MAX); log_filename = SCMalloc(PATH_MAX);
if (log_filename == NULL) if (log_filename == NULL)
return NULL; return NULL;
snprintf(log_filename, PATH_MAX, "%s/%s", log_dir, filearg); snprintf(log_filename, PATH_MAX, "%s/%s", log_dir, filearg);

@ -692,7 +692,7 @@ static inline void SCACGfbsCreateFailureTable(MpmCtx *mpm_ctx)
/* allot space for the failure table. A failure entry in the table for /* allot space for the failure table. A failure entry in the table for
* every state(SCACGfbsCtx->state_count) */ * every state(SCACGfbsCtx->state_count) */
ctx->failure_table = malloc(ctx->state_count * sizeof(int32_t)); ctx->failure_table = SCMalloc(ctx->state_count * sizeof(int32_t));
if (ctx->failure_table == NULL) { if (ctx->failure_table == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -748,7 +748,7 @@ static inline void SCACGfbsCreateModGotoTable(MpmCtx *mpm_ctx)
* but by avoiding it, we save a lot of time on handling alignment */ * but by avoiding it, we save a lot of time on handling alignment */
int size = (ctx->state_count * sizeof(SC_AC_GFBS_STATE_TYPE_U16) * 3 + int size = (ctx->state_count * sizeof(SC_AC_GFBS_STATE_TYPE_U16) * 3 +
256 * sizeof(SC_AC_GFBS_STATE_TYPE_U16) * 2); 256 * sizeof(SC_AC_GFBS_STATE_TYPE_U16) * 2);
ctx->goto_table_mod = malloc(size); ctx->goto_table_mod = SCMalloc(size);
if (ctx->goto_table_mod == NULL) { if (ctx->goto_table_mod == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -760,7 +760,7 @@ static inline void SCACGfbsCreateModGotoTable(MpmCtx *mpm_ctx)
/* buffer to hold pointers in the buffer, so that a state can use it /* buffer to hold pointers in the buffer, so that a state can use it
* directly to access its state data */ * directly to access its state data */
ctx->goto_table_mod_pointers = malloc(ctx->state_count * sizeof(uint8_t *)); ctx->goto_table_mod_pointers = SCMalloc(ctx->state_count * sizeof(uint8_t *));
if (ctx->goto_table_mod_pointers == NULL) { if (ctx->goto_table_mod_pointers == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -804,7 +804,7 @@ static inline void SCACGfbsCreateModGotoTable(MpmCtx *mpm_ctx)
* but by avoiding it, we save a lot of time on handling alignment */ * but by avoiding it, we save a lot of time on handling alignment */
int size = (ctx->state_count * (sizeof(SC_AC_GFBS_STATE_TYPE_U32) * 3) + int size = (ctx->state_count * (sizeof(SC_AC_GFBS_STATE_TYPE_U32) * 3) +
256 * (sizeof(SC_AC_GFBS_STATE_TYPE_U32) * 2)); 256 * (sizeof(SC_AC_GFBS_STATE_TYPE_U32) * 2));
ctx->goto_table_mod = malloc(size); ctx->goto_table_mod = SCMalloc(size);
if (ctx->goto_table_mod == NULL) { if (ctx->goto_table_mod == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -816,7 +816,7 @@ static inline void SCACGfbsCreateModGotoTable(MpmCtx *mpm_ctx)
/* buffer to hold pointers in the buffer, so that a state can use it /* buffer to hold pointers in the buffer, so that a state can use it
* directly to access its state data */ * directly to access its state data */
ctx->goto_table_mod_pointers = malloc(ctx->state_count * sizeof(uint8_t *)); ctx->goto_table_mod_pointers = SCMalloc(ctx->state_count * sizeof(uint8_t *));
if (ctx->goto_table_mod_pointers == NULL) { if (ctx->goto_table_mod_pointers == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -954,7 +954,7 @@ int SCACGfbsPreparePatterns(MpmCtx *mpm_ctx)
//ctx->single_state_size = sizeof(int32_t) * 256; //ctx->single_state_size = sizeof(int32_t) * 256;
/* handle no case patterns */ /* handle no case patterns */
ctx->pid_pat_list = malloc((ctx->max_pat_id + 1)* sizeof(SCACGfbsPatternList)); ctx->pid_pat_list = SCMalloc((ctx->max_pat_id + 1)* sizeof(SCACGfbsPatternList));
if (ctx->pid_pat_list == NULL) { if (ctx->pid_pat_list == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -967,7 +967,7 @@ int SCACGfbsPreparePatterns(MpmCtx *mpm_ctx)
} else { } else {
if (memcmp(ctx->parray[i]->original_pat, ctx->parray[i]->ci, if (memcmp(ctx->parray[i]->original_pat, ctx->parray[i]->ci,
ctx->parray[i]->len) != 0) { ctx->parray[i]->len) != 0) {
ctx->pid_pat_list[ctx->parray[i]->id].cs = malloc(ctx->parray[i]->len); ctx->pid_pat_list[ctx->parray[i]->id].cs = SCMalloc(ctx->parray[i]->len);
if (ctx->pid_pat_list[ctx->parray[i]->id].cs == NULL) { if (ctx->pid_pat_list[ctx->parray[i]->id].cs == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

@ -1496,7 +1496,7 @@ static int B2gCudaMpmStreamDataInit(B2gCudaMpmThreadCtxData *tctx, MpmCudaConf *
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
sd->results_buffer = malloc(sizeof(uint16_t) * sd->results_buffer = SCMalloc(sizeof(uint16_t) *
(profile->packet_size_limit + 1) * (profile->packet_size_limit + 1) *
profile->packet_buffer_limit); profile->packet_buffer_limit);
if (sd->results_buffer == NULL) { if (sd->results_buffer == NULL) {
@ -1680,7 +1680,7 @@ TmEcode B2gCudaMpmDispThreadInit(ThreadVars *tv, void *initdata, void **data)
SCLogError(SC_ERR_B2G_CUDA_ERROR, "Error pushing cuda context"); SCLogError(SC_ERR_B2G_CUDA_ERROR, "Error pushing cuda context");
} }
B2gCudaMpmThreadCtxData *tctx = malloc(sizeof(B2gCudaMpmThreadCtxData)); B2gCudaMpmThreadCtxData *tctx = SCMalloc(sizeof(B2gCudaMpmThreadCtxData));
if (tctx == NULL) { if (tctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -1720,7 +1720,7 @@ TmEcode B2gCudaMpmDispThreadInit(ThreadVars *tv, void *initdata, void **data)
} }
/* Initialize resources for the streams */ /* Initialize resources for the streams */
tctx->stream_data = malloc(tctx->no_of_streams * sizeof(B2gCudaMpmStreamData)); tctx->stream_data = SCMalloc(tctx->no_of_streams * sizeof(B2gCudaMpmStreamData));
if (tctx->stream_data == NULL) { if (tctx->stream_data == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory."); SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -2572,7 +2572,7 @@ static int B2gCudaTest02(void)
memset(p, 0, sizeof(p)); memset(p, 0, sizeof(p));
for (i = 0; i < no_of_pkts; i++) { for (i = 0; i < no_of_pkts; i++) {
p[i] = malloc(SIZE_OF_PACKET); p[i] = SCMalloc(SIZE_OF_PACKET);
if (p[i] == NULL) { if (p[i] == NULL) {
printf("error allocating memory\n"); printf("error allocating memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -2792,7 +2792,7 @@ static int B2gCudaTest03(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
for (i = 0; i < no_of_pkts; i++) { for (i = 0; i < no_of_pkts; i++) {
p[i] = malloc(SIZE_OF_PACKET); p[i] = SCMalloc(SIZE_OF_PACKET);
if (p[i] == NULL) { if (p[i] == NULL) {
printf("error allocating memory\n"); printf("error allocating memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -3115,7 +3115,7 @@ static int B2gCudaTest04(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
for (i = 0; i < no_of_pkts; i++) { for (i = 0; i < no_of_pkts; i++) {
p[i] = malloc(sizeof(Packet)); p[i] = SCMalloc(sizeof(Packet));
if (p[i] == NULL) { if (p[i] == NULL) {
printf("error allocating memory\n"); printf("error allocating memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -3459,7 +3459,7 @@ static int B2gCudaTest05(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
for (i = 0; i < no_of_pkts; i++) { for (i = 0; i < no_of_pkts; i++) {
p[i] = malloc(sizeof(Packet)); p[i] = SCMalloc(sizeof(Packet));
if (p[i] == NULL) { if (p[i] == NULL) {
printf("error allocating memory\n"); printf("error allocating memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

@ -1194,7 +1194,7 @@ ProfilingGenericTicksTest01(void) {
ticks_start = UtilCpuGetTicks(); ticks_start = UtilCpuGetTicks();
for (i = 0; i < TEST_RUNS; i++) { for (i = 0; i < TEST_RUNS; i++) {
ptr[i] = malloc(1024); ptr[i] = SCMalloc(1024);
} }
ticks_end = UtilCpuGetTicks(); ticks_end = UtilCpuGetTicks();
printf("malloc(1024) %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS); printf("malloc(1024) %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);

Loading…
Cancel
Save