From 129fdc526ba4ad6b5bd1f7db296eb11c1a9c75bd Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Fri, 1 Apr 2016 17:09:12 +0200 Subject: [PATCH] match plugins: malloc + memset -> calloc --- src/match_empty_counter.c | 5 ++--- src/match_hashed.c | 5 ++--- src/match_regex.c | 12 +++++------- src/match_timediff.c | 5 ++--- src/match_value.c | 5 ++--- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/match_empty_counter.c b/src/match_empty_counter.c index 4a5dc8c0..8f99a6d1 100644 --- a/src/match_empty_counter.c +++ b/src/match_empty_counter.c @@ -46,13 +46,12 @@ static int mec_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mec_match_t *m; - m = malloc (sizeof (*m)); + m = calloc (1, sizeof (*m)); if (m == NULL) { - ERROR ("mec_create: malloc failed."); + ERROR ("mec_create: calloc failed."); return (-ENOMEM); } - memset (m, 0, sizeof (*m)); if (ci->children_num != 0) { diff --git a/src/match_hashed.c b/src/match_hashed.c index 049dd28d..4178d757 100644 --- a/src/match_hashed.c +++ b/src/match_hashed.c @@ -101,13 +101,12 @@ static int mh_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ mh_match_t *m; int i; - m = malloc (sizeof (*m)); + m = calloc (1, sizeof (*m)); if (m == NULL) { - ERROR ("mh_create: malloc failed."); + ERROR ("mh_create: calloc failed."); return (-ENOMEM); } - memset (m, 0, sizeof (*m)); for (i = 0; i < ci->children_num; i++) { diff --git a/src/match_regex.c b/src/match_regex.c index 7429ffaf..6e6bda2a 100644 --- a/src/match_regex.c +++ b/src/match_regex.c @@ -140,13 +140,12 @@ static int mr_config_add_regex (mr_regex_t **re_head, /* {{{ */ return (-1); } - re = malloc (sizeof (*re)); + re = calloc (1, sizeof (*re)); if (re == NULL) { - log_err ("mr_config_add_regex: malloc failed."); + log_err ("mr_config_add_regex: calloc failed."); return (-1); } - memset (re, 0, sizeof (*re)); re->next = NULL; re->re_str = strdup (ci->values[0].value.string); @@ -194,14 +193,13 @@ static int mr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - m = malloc (sizeof (*m)); + m = calloc (1, sizeof (*m)); if (m == NULL) { - log_err ("mr_create: malloc failed."); + log_err ("mr_create: calloc failed."); return (-ENOMEM); } - memset (m, 0, sizeof (*m)); - + m->invert = 0; status = 0; diff --git a/src/match_timediff.c b/src/match_timediff.c index 2b5f530a..77c8f519 100644 --- a/src/match_timediff.c +++ b/src/match_timediff.c @@ -52,13 +52,12 @@ static int mt_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - m = malloc (sizeof (*m)); + m = calloc (1, sizeof (*m)); if (m == NULL) { - ERROR ("mt_create: malloc failed."); + ERROR ("mt_create: calloc failed."); return (-ENOMEM); } - memset (m, 0, sizeof (*m)); m->future = 0; m->past = 0; diff --git a/src/match_value.c b/src/match_value.c index 9b13aa86..8c6fd36c 100644 --- a/src/match_value.c +++ b/src/match_value.c @@ -200,13 +200,12 @@ static int mv_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - m = malloc (sizeof (*m)); + m = calloc (1, sizeof (*m)); if (m == NULL) { - ERROR ("mv_create: malloc failed."); + ERROR ("mv_create: calloc failed."); return (-ENOMEM); } - memset (m, 0, sizeof (*m)); m->min = NAN; m->max = NAN; -- 2.30.2