From 9f7822ccdc208dcec0dd141fa529b8e170c10372 Mon Sep 17 00:00:00 2001 From: stuart nelson Date: Sun, 18 Sep 2016 16:17:49 +0200 Subject: [PATCH] Remember to bzero string Duplication was caused by malloc returning a region of memory that already had data in it. --- collector/cpu_dragonfly.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/collector/cpu_dragonfly.go b/collector/cpu_dragonfly.go index d51cfe5d..fe9e0cf9 100644 --- a/collector/cpu_dragonfly.go +++ b/collector/cpu_dragonfly.go @@ -82,7 +82,9 @@ getCPUTimes(int *ncpu, char **cputime) { // string needs to hold (5*ncpu)(uint64_t + char) // The char is the space between values. - *cputime = (char *) malloc((sizeof(uint64_t)+sizeof(char))*(5*(*ncpu))); + int cputime_size = (sizeof(uint64_t)+sizeof(char))*(5*(*ncpu)); + *cputime = (char *) malloc(cputime_size); + bzero(*cputime, cputime_size); uint64_t user, nice, sys, intr, idle; user = nice = sys = intr = idle = 0;