use defer to close smart stream

This commit is contained in:
rare-magma 2022-06-08 18:37:41 +02:00
parent 7f90fef354
commit 3704569b81

View File

@ -45,19 +45,19 @@ func getTemps(temps map[string]int) map[string]error {
log.Println(err) log.Println(err)
continue continue
} }
defer dev.Close()
switch sm := dev.(type) { switch sm := dev.(type) {
case *smart.SataDevice: case *smart.SataDevice:
data, _ := sm.ReadSMARTData() data, _ := sm.ReadSMARTData()
for _, attr := range data.Attrs { for _, attr := range data.Attrs {
if attr.Id == 194 { if attr.Id == 194 {
temps[disk.Name+"_"+disk.Model] = int(attr.Value) temps[disk.Name+"_"+disk.Model] = int(attr.Value)
sm.Close()
} }
} }
case *smart.NVMeDevice: case *smart.NVMeDevice:
data, _ := sm.ReadSMART() data, _ := sm.ReadSMART()
temps[disk.Name+"_"+disk.Model] = int(data.Temperature) temps[disk.Name+"_"+disk.Model] = int(data.Temperature)
sm.Close()
default: default:
} }
} }