Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
thechampagne authored Jun 2, 2024
1 parent 184fb1c commit e19951c
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 e19951c

Please sign in to comment.