barometer plugin: Fix allocation size.
authorFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 06:35:22 +0000 (08:35 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 06:35:47 +0000 (08:35 +0200)
src/barometer.c

index 2bfd51e..c1a7fa9 100644 (file)
@@ -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; a<size; ++a)
-    {
-      avg->ring_buffer[a] = 0L;
-    }
-
     avg->ring_buffer_size = size;
     avg->ring_buffer_sum  = 0L;
     avg->ring_buffer_head = 0;