From: Florian Forster Date: Wed, 17 Jun 2015 06:35:22 +0000 (+0200) Subject: barometer plugin: Fix allocation size. X-Git-Tag: collectd-5.5.1~112 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4bb6f36477cf997c81ee5eeda16990cf26e6b04d;p=collectd.git barometer plugin: Fix allocation size. --- diff --git a/src/barometer.c b/src/barometer.c index 2bfd51e0..c1a7fa94 100644 --- a/src/barometer.c +++ b/src/barometer.c @@ -253,11 +253,9 @@ static averaging_t temperature_averaging = { NULL, 0, 0L, 0 }; * * @return Zero when successful */ -static int averaging_create(averaging_t * avg, int size) +static int averaging_create(averaging_t *avg, int size) { - int a; - - avg->ring_buffer = (long int *) malloc(size * sizeof(*avg)); + avg->ring_buffer = calloc ((size_t) size, sizeof (*avg)); if (avg->ring_buffer == NULL) { ERROR ("barometer: averaging_create - ring buffer allocation of size %d failed", @@ -265,11 +263,6 @@ static int averaging_create(averaging_t * avg, int size) return -1; } - for (a=0; aring_buffer[a] = 0L; - } - avg->ring_buffer_size = size; avg->ring_buffer_sum = 0L; avg->ring_buffer_head = 0;