Skip to content

Commit

Permalink
Merge pull request #1656 from thechampagne/master
Browse files Browse the repository at this point in the history
fix memory leak
  • Loading branch information
shirou authored Jun 3, 2024
2 parents 184fb1c + e19951c commit 29699cd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sensors/sensors_darwin_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ package sensors
// #cgo LDFLAGS: -framework IOKit
// #include "smc_darwin.h"
import "C"
import "context"
import (
"context"
"unsafe"
)

func TemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
temperatureKeys := []string{
Expand Down Expand Up @@ -38,9 +41,11 @@ func TemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
defer C.gopsutil_v4_close_smc()

for _, key := range temperatureKeys {
ckey := C.CString(key)
defer C.free(unsafe.Pointer(ckey))
temperatures = append(temperatures, TemperatureStat{
SensorKey: key,
Temperature: float64(C.gopsutil_v4_get_temperature(C.CString(key))),
Temperature: float64(C.gopsutil_v4_get_temperature(ckey)),
})
}
return temperatures, nil
Expand Down

0 comments on commit 29699cd

Please sign in to comment.