From 60a2668788c25f58cad5d1e97ed220dfb7e6e74a Mon Sep 17 00:00:00 2001 From: Matt Oshry <55526879+splmatto@users.noreply.github.com> Date: Mon, 29 Nov 2021 01:55:36 -0800 Subject: [PATCH] Handle nil CPU thermal power status on M1 (#2225) Signed-off-by: Matt Oshry --- CHANGELOG.md | 2 ++ collector/thermal_darwin.go | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 675057ec08..a152600b27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * [ENHANCEMENT] * [BUGFIX] +* [BUGFIX] Handle nil CPU thermal power status on M1 #2218 + ## 1.3.0 / 2021-10-20 NOTE: In order to support globs in the textfile collector path, filenames exposed by diff --git a/collector/thermal_darwin.go b/collector/thermal_darwin.go index 282ca3f383..25673dcc4d 100644 --- a/collector/thermal_darwin.go +++ b/collector/thermal_darwin.go @@ -47,9 +47,10 @@ import "C" import ( "errors" "fmt" + "unsafe" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" - "unsafe" ) type thermCollector struct { @@ -118,7 +119,9 @@ func (c *thermCollector) Update(ch chan<- prometheus.Metric) error { func fetchCPUPowerStatus() (map[string]int, error) { cfDictRef, _ := C.FetchThermal() defer func() { - C.CFRelease(C.CFTypeRef(cfDictRef.ref)) + if cfDictRef.ref != 0x0 { + C.CFRelease(C.CFTypeRef(cfDictRef.ref)) + } }() if C.kIOReturnNotFound == cfDictRef.ret {