From 15a71f32fe1636d24bc8c2ae5e1eb689d2e28c7e Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Wed, 7 Jul 2021 14:00:36 +1000 Subject: [PATCH] Add more defensive checks to PCP paths if sampling fails --- pcp/Platform.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pcp/Platform.c b/pcp/Platform.c index f10b128b..215a3ee0 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -336,6 +336,9 @@ pmAtomValue *Metric_instance(Metric metric, int inst, int offset, pmAtomValue *a * Start it off by passing offset -1 into the routine. */ bool Metric_iterate(Metric metric, int* instp, int* offsetp) { + if (!pcp->result) + return false; + pmValueSet* vset = pcp->result->vset[metric]; if (!vset || vset->numval <= 0) return false; @@ -892,8 +895,12 @@ void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { } void Platform_gettime_monotonic(uint64_t* msec) { - struct timeval* tv = &pcp->result->timestamp; - *msec = ((uint64_t)tv->tv_sec * 1000) + ((uint64_t)tv->tv_usec / 1000); + if (pcp->result) { + struct timeval* tv = &pcp->result->timestamp; + *msec = ((uint64_t)tv->tv_sec * 1000) + ((uint64_t)tv->tv_usec / 1000); + } else { + *msec = 0; + } } Hashtable* Platform_dynamicMeters(void) {