From: Jeff Lucovsky Date: Wed, 26 Jul 2023 12:38:13 +0000 (-0400) Subject: mem/alloc: Replace malloc with calloc X-Git-Tag: suricata-7.0.1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3499029d404a11756fa9fcf213c1b58f0ad95f6b;p=thirdparty%2Fsuricata.git mem/alloc: Replace malloc with calloc Minor cleanup so SCCalloc is used in preference to SCMalloc. --- diff --git a/src/counters.c b/src/counters.c index c13be8584a..7acdeae626 100644 --- a/src/counters.c +++ b/src/counters.c @@ -604,9 +604,8 @@ static uint16_t StatsRegisterQualifiedCounter(const char *name, const char *tm_n return(temp->id); /* if we reach this point we don't have a counter registered by this name */ - if ( (pc = SCMalloc(sizeof(StatsCounter))) == NULL) + if ((pc = SCCalloc(1, sizeof(StatsCounter))) == NULL) return 0; - memset(pc, 0, sizeof(StatsCounter)); /* assign a unique id to this StatsCounter. The id is local to this * thread context. Please note that the id start from 1, and not 0 */ @@ -878,10 +877,9 @@ static void StatsLogSummary(void) void StatsInit(void) { BUG_ON(stats_ctx != NULL); - if ( (stats_ctx = SCMalloc(sizeof(StatsGlobalContext))) == NULL) { + if ((stats_ctx = SCCalloc(1, sizeof(StatsGlobalContext))) == NULL) { FatalError("Fatal error encountered in StatsInitCtx. Exiting..."); } - memset(stats_ctx, 0, sizeof(StatsGlobalContext)); StatsPublicThreadContextInit(&stats_ctx->global_counter_ctx); } @@ -1118,11 +1116,10 @@ static int StatsThreadRegister(const char *thread_name, StatsPublicThreadContext StatsThreadStore *temp = NULL; - if ( (temp = SCMalloc(sizeof(StatsThreadStore))) == NULL) { + if ((temp = SCCalloc(1, sizeof(StatsThreadStore))) == NULL) { SCMutexUnlock(&stats_ctx->sts_lock); return 0; } - memset(temp, 0, sizeof(StatsThreadStore)); temp->ctx = pctx; temp->name = thread_name; @@ -1167,10 +1164,9 @@ static int StatsGetCounterArrayRange(uint16_t s_id, uint16_t e_id, return -1; } - if ( (pca->head = SCMalloc(sizeof(StatsLocalCounter) * (e_id - s_id + 2))) == NULL) { + if ((pca->head = SCCalloc(1, sizeof(StatsLocalCounter) * (e_id - s_id + 2))) == NULL) { return -1; } - memset(pca->head, 0, sizeof(StatsLocalCounter) * (e_id - s_id + 2)); pc = pctx->head; while (pc->id != s_id)