X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Faggregation.c;h=3d5f396aa53ad453db5e320b12a0b9f9c9e56d63;hb=42ca41a0798e3a2b742f7da3bacc03fbaf6175fa;hp=8175c66c18fb14ded8b5a4be282a9cf4e1a418c0;hpb=f2389f97fbec15f49dcd1d9b06b3b6bbd0837e8a;p=collectd.git diff --git a/src/aggregation.c b/src/aggregation.c index 8175c66c..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,13 +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); \ - ERROR ("aggregation plugin: malloc() failed."); \ + free (inst); \ + ERROR ("aggregation plugin: calloc() failed."); \ return (NULL); \ } \ - memset (inst->state_ ## field, 0, sizeof (*inst->state_ ## field)); \ } \ } while (0) @@ -527,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));