diff --git a/src/cmd/internal/cov/readcovdata.go b/src/cmd/internal/cov/readcovdata.go index 086be40e903..e0e06344595 100644 --- a/src/cmd/internal/cov/readcovdata.go +++ b/src/cmd/internal/cov/readcovdata.go @@ -204,15 +204,12 @@ func (r *CovDataReader) visitPod(p pods.Pod) error { } r.vis.VisitMetaDataFile(p.MetaFile, mfr) - // Read counter data files. - for k, cdf := range p.CounterDataFiles { + processCounterDataFile := func(cdf string, k int) error { cf, err := os.Open(cdf) if err != nil { return r.fatal("opening counter data file %s: %s", cdf, err) } - defer func(f *os.File) { - f.Close() - }(cf) + defer cf.Close() var mr *MReader mr, err = NewMreader(cf) if err != nil { @@ -236,6 +233,14 @@ func (r *CovDataReader) visitPod(p pods.Pod) error { r.vis.VisitFuncCounterData(data) } r.vis.EndCounterDataFile(cdf, cdr, p.Origins[k]) + return nil + } + + // Read counter data files. + for k, cdf := range p.CounterDataFiles { + if err := processCounterDataFile(cdf, k); err != nil { + return err + } } r.vis.EndCounters()