From: Florian Forster Date: Sat, 18 Apr 2009 11:12:23 +0000 (+0200) Subject: memory plugin: Check `pagesize' when initializing, not when reading. X-Git-Tag: collectd-4.7.0~58 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=427d99e60f2a9b3b1e6b62b1d5fd36d6512f991b;p=collectd.git memory plugin: Check `pagesize' when initializing, not when reading. --- diff --git a/src/memory.c b/src/memory.c index 0926c595..d6c3c888 100644 --- a/src/memory.c +++ b/src/memory.c @@ -87,6 +87,11 @@ static int memory_init (void) #elif HAVE_SYSCTL pagesize = getpagesize (); + if (pagesize <= 0) + { + ERROR ("memory plugin: Invalid pagesize: %i", pagesize); + return (-1); + } /* #endif HAVE_SYSCTL */ #elif HAVE_SYSCTLBYNAME @@ -187,12 +192,6 @@ static int memory_read (void) struct vmtotal vmtotal; size_t size; - if (pagesize <= 0) - { - ERROR ("memory plugin: Invalid pagesize: %i", pagesize); - return (-1); - } - memset (&vmtotal, 0, sizeof (vmtotal)); size = sizeof (vmtotal); @@ -203,6 +202,7 @@ static int memory_read (void) return (-1); } + assert (pagesize > 0); memory_submit ("active", vmtotal.t_arm * pagesize); memory_submit ("inactive", (vmtotal.t_rm - vmtotal.t_arm) * pagesize); memory_submit ("free", vmtotal.t_free * pagesize);