From ed77b95632a3709e49ee9ff10bb4ae41bab3ef0e Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 27 Aug 2004 23:06:46 +0000 Subject: [PATCH] fix possible crash in get_cpu_instance --- src/os/win32/win32_sigar.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index 57634b42..60f13938 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -294,6 +294,15 @@ static PERF_INSTANCE_DEFINITION *get_cpu_instance(sigar_t *sigar, return NULL; } + /* XXX dont know why this happens, seen on + * 2003 server mail.hyperic.net + */ + + if (object->NumInstances < 1) { + *err = ENOENT; + return NULL; + } + for (i=0, counter = PdhFirstCounter(object); iNumCounters; i++, counter = PdhNextCounter(counter)) @@ -332,7 +341,7 @@ SIGAR_DECLARE(int) sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu) inst = get_cpu_instance(sigar, (DWORD*)&perf_offsets, 0, &err); if (!inst) { - return GetLastError(); + return err; } /* first instance is total, rest are per-cpu */