From: Ruben Kerkhof Date: Mon, 28 Mar 2016 17:31:17 +0000 (+0200) Subject: aggregration: malloc + memset -> calloc X-Git-Tag: collectd-5.6.0~371^2~52 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=039aa55eb12580edecb06a23f6c7a9286c5e0ad0;p=collectd.git aggregration: malloc + memset -> calloc --- diff --git a/src/aggregation.c b/src/aggregation.c index 56e4955c..3d5f396a 100644 --- a/src/aggregation.c +++ b/src/aggregation.c @@ -240,13 +240,12 @@ static agg_instance_t *agg_instance_create (data_set_t const *ds, /* {{{ */ DEBUG ("aggregation plugin: Creating new instance."); - inst = malloc (sizeof (*inst)); + inst = calloc (1, sizeof (*inst)); if (inst == NULL) { - ERROR ("aggregation plugin: malloc() failed."); + ERROR ("aggregation plugin: calloc() failed."); return (NULL); } - memset (inst, 0, sizeof (*inst)); pthread_mutex_init (&inst->lock, /* attr = */ NULL); inst->ds_type = ds->ds[0].type; @@ -259,14 +258,13 @@ static agg_instance_t *agg_instance_create (data_set_t const *ds, /* {{{ */ #define INIT_STATE(field) do { \ inst->state_ ## field = NULL; \ if (agg->calc_ ## field) { \ - inst->state_ ## field = malloc (sizeof (*inst->state_ ## field)); \ + inst->state_ ## field = calloc (1, sizeof (*inst->state_ ## field)); \ if (inst->state_ ## field == NULL) { \ agg_instance_destroy (inst); \ free (inst); \ - ERROR ("aggregation plugin: malloc() failed."); \ + ERROR ("aggregation plugin: calloc() failed."); \ return (NULL); \ } \ - memset (inst->state_ ## field, 0, sizeof (*inst->state_ ## field)); \ } \ } while (0) @@ -528,13 +526,12 @@ static int agg_config_aggregation (oconfig_item_t *ci) /* {{{ */ int status; int i; - agg = malloc (sizeof (*agg)); + agg = calloc (1, sizeof (*agg)); if (agg == NULL) { - ERROR ("aggregation plugin: malloc failed."); + ERROR ("aggregation plugin: calloc failed."); return (-1); } - memset (agg, 0, sizeof (*agg)); sstrncpy (agg->ident.host, "/.*/", sizeof (agg->ident.host)); sstrncpy (agg->ident.plugin, "/.*/", sizeof (agg->ident.plugin));