Skip to content

Commit

Permalink
Handle nil CPU thermal power status on M1 (#2225)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Oshry <matto@spatialinc.com>
  • Loading branch information
splmatto authored Nov 29, 2021
1 parent 9fbb56c commit 60a2668
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions collector/thermal_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 60a2668

Please sign in to comment.