From 13ea299ee08e73dfe242f5c92196066981f3d295 Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Thu, 22 Sep 2011 16:52:28 +0530 Subject: [PATCH] Replace all mallocs with SCMallocs --- src/app-layer-dcerpc-udp.c | 2 +- src/cuda-packet-batcher.c | 12 ++++++------ src/detect-bytejump.c | 2 +- src/detect-bytetest.c | 2 +- src/detect-fast-pattern.c | 4 ++-- src/util-cuda-handlers.c | 4 ++-- src/util-debug.c | 12 ++++++------ src/util-mpm-ac-gfbs.c | 14 +++++++------- src/util-mpm-b2g-cuda.c | 18 +++++++++--------- src/util-profiling.c | 2 +- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/app-layer-dcerpc-udp.c b/src/app-layer-dcerpc-udp.c index 5b65ca3611..a64465bab8 100644 --- a/src/app-layer-dcerpc-udp.c +++ b/src/app-layer-dcerpc-udp.c @@ -676,7 +676,7 @@ static int DCERPCUDPParse(Flow *f, void *dcerpc_state, } static void *DCERPCUDPStateAlloc(void) { - void *s = malloc(sizeof(DCERPCUDPState)); + void *s = SCMalloc(sizeof(DCERPCUDPState)); if (s == NULL) return NULL; diff --git a/src/cuda-packet-batcher.c b/src/cuda-packet-batcher.c index e4f103d0b0..b219f971f9 100644 --- a/src/cuda-packet-batcher.c +++ b/src/cuda-packet-batcher.c @@ -434,7 +434,7 @@ void SCCudaPBDeAllocSCCudaPBPacketsBuffer(SCCudaPBPacketsBuffer *pb) */ SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void) { - SCCudaPBPacketsBuffer *pb = malloc(sizeof(SCCudaPBPacketsBuffer)); + SCCudaPBPacketsBuffer *pb = SCMalloc(sizeof(SCCudaPBPacketsBuffer)); if (pb == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); @@ -480,7 +480,7 @@ SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void) exit(EXIT_FAILURE); } } else { - pb->packets_buffer = malloc(profile->packet_buffer_limit * + pb->packets_buffer = SCMalloc(profile->packet_buffer_limit * (profile->packet_size_limit + sizeof(SCCudaPBPacketDataForGPUNonPayload))); if (pb->packets_buffer == NULL) { @@ -501,7 +501,7 @@ SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void) exit(EXIT_FAILURE); } } else { - pb->packets_offset_buffer = malloc(sizeof(uint32_t) * + pb->packets_offset_buffer = SCMalloc(sizeof(uint32_t) * profile->packet_buffer_limit); if (pb->packets_offset_buffer == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); @@ -521,7 +521,7 @@ SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void) exit(EXIT_FAILURE); } } else { - pb->packets_payload_offset_buffer = malloc(sizeof(uint32_t) * + pb->packets_payload_offset_buffer = SCMalloc(sizeof(uint32_t) * profile->packet_buffer_limit); if (pb->packets_payload_offset_buffer == NULL) { 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 * packets_buffer */ - pb->packets_address_buffer = malloc(sizeof(Packet *) * + pb->packets_address_buffer = SCMalloc(sizeof(Packet *) * profile->packet_buffer_limit); if (pb->packets_address_buffer == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); @@ -586,7 +586,7 @@ TmEcode SCCudaPBThreadInit(ThreadVars *tv, void *initdata, void **data) return TM_ECODE_FAILED; } - tctx = malloc(sizeof(SCCudaPBThreadCtx)); + tctx = SCMalloc(sizeof(SCCudaPBThreadCtx)); if (tctx == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); diff --git a/src/detect-bytejump.c b/src/detect-bytejump.c index 58e8ec3629..e7ab4596f4 100644 --- a/src/detect-bytejump.c +++ b/src/detect-bytejump.c @@ -1159,7 +1159,7 @@ int DetectByteJumpTestPacket03(void) int result = 0; uint8_t *buf = NULL; uint16_t buflen = 0; - buf = malloc(4); + buf = SCMalloc(4); if (buf == NULL) { printf("malloc failed\n"); exit(EXIT_FAILURE); diff --git a/src/detect-bytetest.c b/src/detect-bytetest.c index 3755c27590..6f7166bb22 100644 --- a/src/detect-bytetest.c +++ b/src/detect-bytetest.c @@ -1446,7 +1446,7 @@ int DetectByteTestTestPacket03(void) int result = 0; uint8_t *buf = NULL; uint16_t buflen = 0; - buf = malloc(4); + buf = SCMalloc(4); if (buf == NULL) { printf("malloc failed\n"); exit(EXIT_FAILURE); diff --git a/src/detect-fast-pattern.c b/src/detect-fast-pattern.c index aa2c8e7363..a2411ed478 100644 --- a/src/detect-fast-pattern.c +++ b/src/detect-fast-pattern.c @@ -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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); diff --git a/src/util-cuda-handlers.c b/src/util-cuda-handlers.c index 2204a3aacb..a9165cd122 100644 --- a/src/util-cuda-handlers.c +++ b/src/util-cuda-handlers.c @@ -117,7 +117,7 @@ void SCCudaHlGetYamlConf(void) SCCudaHlCudaProfile *profile = NULL; /* "mpm" profile, found under "cuda.mpm" in the conf file */ - profile = malloc(sizeof(SCCudaHlCudaProfile)); + profile = SCMalloc(sizeof(SCCudaHlCudaProfile)); if (profile == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); 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 * devices (i.e. the lowest) */ - char* image = malloc(strlen(ptx_image)+15); + char* image = SCMalloc(strlen(ptx_image)+15); memset(image, 0x0, sizeof(image)); int major = INT_MAX; diff --git a/src/util-debug.c b/src/util-debug.c index 6e3464b746..4a96db50f4 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -492,7 +492,7 @@ 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) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAllocLogOPBuffer. Exiting..."); exit(EXIT_FAILURE); @@ -521,7 +521,7 @@ static inline SCLogOPIfaceCtx *SCLogAllocLogOPIfaceCtx() { 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..."); exit(EXIT_FAILURE); } @@ -935,7 +935,7 @@ SCLogInitData *SCLogAllocLogInitData(void) SCLogInitData *sc_lid = NULL; /* 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; memset(sc_lid, 0, sizeof(SCLogInitData)); @@ -1086,7 +1086,7 @@ void SCLogInitLogModule(SCLogInitData *sc_lid) #endif /* OS_WIN32 */ /* 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..."); exit(EXIT_FAILURE); } @@ -1237,7 +1237,7 @@ void SCLogInitLogModuleIfEnvSet(void) SCLogLevel log_level = SC_LOG_NOTSET; /* sc_log_config is a global variable */ - if ( (sc_log_config = malloc(sizeof(SCLogConfig))) == NULL) + if ( (sc_log_config = SCMalloc(sizeof(SCLogConfig))) == NULL) return; memset(sc_log_config, 0, sizeof(SCLogConfig)); sc_lc = sc_log_config; @@ -1363,7 +1363,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); diff --git a/src/util-mpm-ac-gfbs.c b/src/util-mpm-ac-gfbs.c index e22a596377..8d3b51baef 100644 --- a/src/util-mpm-ac-gfbs.c +++ b/src/util-mpm-ac-gfbs.c @@ -692,7 +692,7 @@ static inline void SCACGfbsCreateFailureTable(MpmCtx *mpm_ctx) /* allot space for the failure table. A failure entry in the table for * 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); 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 */ int size = (ctx->state_count * sizeof(SC_AC_GFBS_STATE_TYPE_U16) * 3 + 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); 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 * 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); 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 */ int size = (ctx->state_count * (sizeof(SC_AC_GFBS_STATE_TYPE_U32) * 3) + 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); 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 * 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); @@ -954,7 +954,7 @@ int SCACGfbsPreparePatterns(MpmCtx *mpm_ctx) //ctx->single_state_size = sizeof(int32_t) * 256; /* 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); @@ -967,7 +967,7 @@ int SCACGfbsPreparePatterns(MpmCtx *mpm_ctx) } else { if (memcmp(ctx->parray[i]->original_pat, ctx->parray[i]->ci, 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c index f20328f246..fde0663a56 100644 --- a/src/util-mpm-b2g-cuda.c +++ b/src/util-mpm-b2g-cuda.c @@ -1496,9 +1496,9 @@ static int B2gCudaMpmStreamDataInit(B2gCudaMpmThreadCtxData *tctx, MpmCudaConf * exit(EXIT_FAILURE); } } else { - sd->results_buffer = malloc(sizeof(uint16_t) * - (profile->packet_size_limit + 1) * - profile->packet_buffer_limit); + sd->results_buffer = SCMalloc(sizeof(uint16_t) * + (profile->packet_size_limit + 1) * + profile->packet_buffer_limit); if (sd->results_buffer == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); @@ -1680,7 +1680,7 @@ TmEcode B2gCudaMpmDispThreadInit(ThreadVars *tv, void *initdata, void **data) SCLogError(SC_ERR_B2G_CUDA_ERROR, "Error pushing cuda context"); } - B2gCudaMpmThreadCtxData *tctx = malloc(sizeof(B2gCudaMpmThreadCtxData)); + B2gCudaMpmThreadCtxData *tctx = SCMalloc(sizeof(B2gCudaMpmThreadCtxData)); if (tctx == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); @@ -1720,7 +1720,7 @@ TmEcode B2gCudaMpmDispThreadInit(ThreadVars *tv, void *initdata, void **data) } /* 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) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory."); exit(EXIT_FAILURE); @@ -2572,7 +2572,7 @@ static int B2gCudaTest02(void) memset(p, 0, sizeof(p)); for (i = 0; i < no_of_pkts; i++) { - p[i] = malloc(SIZE_OF_PACKET); + p[i] = SCMalloc(SIZE_OF_PACKET); if (p[i] == NULL) { printf("error allocating memory\n"); exit(EXIT_FAILURE); @@ -2792,7 +2792,7 @@ static int B2gCudaTest03(void) FlowInitConfig(FLOW_QUIET); for (i = 0; i < no_of_pkts; i++) { - p[i] = malloc(SIZE_OF_PACKET); + p[i] = SCMalloc(SIZE_OF_PACKET); if (p[i] == NULL) { printf("error allocating memory\n"); exit(EXIT_FAILURE); @@ -3115,7 +3115,7 @@ static int B2gCudaTest04(void) FlowInitConfig(FLOW_QUIET); for (i = 0; i < no_of_pkts; i++) { - p[i] = malloc(sizeof(Packet)); + p[i] = SCMalloc(sizeof(Packet)); if (p[i] == NULL) { printf("error allocating memory\n"); exit(EXIT_FAILURE); @@ -3459,7 +3459,7 @@ static int B2gCudaTest05(void) FlowInitConfig(FLOW_QUIET); for (i = 0; i < no_of_pkts; i++) { - p[i] = malloc(sizeof(Packet)); + p[i] = SCMalloc(sizeof(Packet)); if (p[i] == NULL) { printf("error allocating memory\n"); exit(EXIT_FAILURE); diff --git a/src/util-profiling.c b/src/util-profiling.c index c2662359eb..8de2c702c5 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -1194,7 +1194,7 @@ ProfilingGenericTicksTest01(void) { ticks_start = UtilCpuGetTicks(); for (i = 0; i < TEST_RUNS; i++) { - ptr[i] = malloc(1024); + ptr[i] = SCMalloc(1024); } ticks_end = UtilCpuGetTicks(); printf("malloc(1024) %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);