From: Ruben Kerkhof Date: Fri, 1 Apr 2016 15:09:12 +0000 (+0200) Subject: match plugins: malloc + memset -> calloc X-Git-Tag: collectd-5.6.0~371^2~34 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=129fdc526ba4ad6b5bd1f7db296eb11c1a9c75bd;p=collectd.git match plugins: malloc + memset -> calloc --- 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;