X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Faggregation.c;h=c4c1627af360ce463ba030cb64e80a4f6667b723;hb=edd9af8a874ebc9f2a7f02846807229a648917db;hp=8175c66c18fb14ded8b5a4be282a9cf4e1a418c0;hpb=443afcad2cbacaca9bb1fd7d9ea790cbeb6ff015;p=collectd.git diff --git a/src/aggregation.c b/src/aggregation.c index 8175c66c..c4c1627a 100644 --- a/src/aggregation.c +++ b/src/aggregation.c @@ -26,8 +26,6 @@ #include "collectd.h" -#include - #include "plugin.h" #include "common.h" #include "configfile.h" @@ -240,13 +238,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 +256,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 +524,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));