Fix: Close file /proc/cpuinfo only once

This commit is contained in:
Holger Obermaier
2026-02-20 14:01:51 +01:00
parent 539581f952
commit d639c942d5

View File

@@ -86,10 +86,6 @@ func (m *CPUFreqCpuInfoCollector) Init(_ json.RawMessage) error {
} }
} }
if err := file.Close(); err != nil {
return fmt.Errorf("%s Init(): Call to file.Close() failed: %w", m.name, err)
}
// were all topology information collected? // were all topology information collected?
if foundFreq && if foundFreq &&
len(processor) > 0 && len(processor) > 0 &&
@@ -121,6 +117,10 @@ func (m *CPUFreqCpuInfoCollector) Init(_ json.RawMessage) error {
} }
} }
if err := file.Close(); err != nil {
return fmt.Errorf("%s Init(): Call to file.Close() failed: %w", m.name, err)
}
// Check if at least one CPU with frequency information was detected // Check if at least one CPU with frequency information was detected
if len(m.topology) == 0 { if len(m.topology) == 0 {
return fmt.Errorf("%s Init(): no CPU frequency info found in %s", m.name, cpuInfoFile) return fmt.Errorf("%s Init(): no CPU frequency info found in %s", m.name, cpuInfoFile)