From: Florian Forster Date: Tue, 4 Jun 2013 06:35:09 +0000 (+0200) Subject: zfs_arc plugin: Use a buffer with fixed size rather than allocating on the heap. X-Git-Tag: collectd-5.4.0~29^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bf7aa5373cb298dbb11e9576a1371cdfaaab7d90;p=collectd.git zfs_arc plugin: Use a buffer with fixed size rather than allocating on the heap. The key length is very predicable, so buffer length is not a problem. --- diff --git a/src/zfs_arc.c b/src/zfs_arc.c index cd0c8414..6bf7daef 100644 --- a/src/zfs_arc.c +++ b/src/zfs_arc.c @@ -49,23 +49,19 @@ const char zfs_arcstat[] = "kstat.zfs.misc.arcstats."; typedef void kstat_t; #endif -static long long get_zfs_value(void * dummy __unused, const char *kstat_value) +static long long get_zfs_value(kstat_t *dummy __attribute__((unused)), + char const *name) { + char buffer[256]; long long value; size_t valuelen = sizeof(value); int rv; - char *key; - - key = ssnprintf_alloc("%s%s", zfs_arcstat, kstat_value); - if (key != NULL) { - if (strlen(key) > 0) { - rv = sysctlbyname(key, (void *)&value, &valuelen, NULL, (size_t)0); - free(key); - if (rv == 0) - return (value); - } else - free(key); - } + + ssnprintf (buffer, sizeof (buffer), "%s%s", zfs_arcstat, name); + rv = sysctlbyname (buffer, (void *) &value, &valuelen, + /* new value = */ NULL, /* new length = */ (size_t) 0); + if (rv == 0) + return (value); return (-1); }