Fix hypotetical file leakage in cputemp.go
This commit is contained in:
@@ -36,38 +36,31 @@ func (c *MyConfig) UpdateCPUTemperature() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to open %s: %s", filename, err)
|
log.Printf("Unable to open %s: %s", filename, err)
|
||||||
} else {
|
continue
|
||||||
reader := bufio.NewReader(file)
|
|
||||||
line, _, err := reader.ReadLine()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Unable to read from %s: %s", filename, err)
|
|
||||||
err = file.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Unable to close %s: %s", filename, err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = file.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Unable to close %s: %s", filename, err)
|
|
||||||
} else {
|
|
||||||
temp, err := strconv.ParseInt(string(line), 10, 32)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Unable to convert string to number from file %s: %s", filename, err)
|
|
||||||
} else {
|
|
||||||
if temp > 1000 {
|
|
||||||
temp /= 1000
|
|
||||||
}
|
|
||||||
|
|
||||||
temperature[i] = temp
|
|
||||||
validCount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
reader := bufio.NewReader(file)
|
||||||
|
line, _, err := reader.ReadLine()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Unable to read from %s: %s", filename, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
temp, err := strconv.ParseInt(string(line), 10, 32)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Unable to convert string to number from file %s: %s", filename, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if temp > 1000 {
|
||||||
|
temp /= 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
temperature[i] = temp
|
||||||
|
validCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
if validCount == 0 {
|
if validCount == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user