Handle nil CPU thermal power status on M1 (#2225)

Signed-off-by: Matt Oshry <matto@spatialinc.com>
This commit is contained in:
Matt Oshry 2021-11-29 01:55:36 -08:00 committed by GitHub
parent 9fbb56c9c8
commit 60a2668788
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -5,6 +5,8 @@
* [ENHANCEMENT] * [ENHANCEMENT]
* [BUGFIX] * [BUGFIX]
* [BUGFIX] Handle nil CPU thermal power status on M1 #2218
## 1.3.0 / 2021-10-20 ## 1.3.0 / 2021-10-20
NOTE: In order to support globs in the textfile collector path, filenames exposed by NOTE: In order to support globs in the textfile collector path, filenames exposed by

View File

@ -47,9 +47,10 @@ import "C"
import ( import (
"errors" "errors"
"fmt" "fmt"
"unsafe"
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"unsafe"
) )
type thermCollector struct { type thermCollector struct {
@ -118,7 +119,9 @@ func (c *thermCollector) Update(ch chan<- prometheus.Metric) error {
func fetchCPUPowerStatus() (map[string]int, error) { func fetchCPUPowerStatus() (map[string]int, error) {
cfDictRef, _ := C.FetchThermal() cfDictRef, _ := C.FetchThermal()
defer func() { defer func() {
C.CFRelease(C.CFTypeRef(cfDictRef.ref)) if cfDictRef.ref != 0x0 {
C.CFRelease(C.CFTypeRef(cfDictRef.ref))
}
}() }()
if C.kIOReturnNotFound == cfDictRef.ret { if C.kIOReturnNotFound == cfDictRef.ret {