runtime/coverage: add missing file close in test support helper

The processPod() helper (invoked by processCoverTestDir, which is in
turn called by _testmain.go) was opening and reading counter data
files, but never closing them. Add a call to close the files after
they have been read.

Fixes #57407.

Change-Id: If9a489f92e4bab72c5b2df8697e14420a6f7b8f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/458835
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Than McIntosh 2022-12-21 11:03:16 -05:00
parent c9a10d48a8
commit fadd77c05b
1 changed files with 13 additions and 2 deletions

View File

@ -136,13 +136,16 @@ func (ts *tstate) processPod(p pods.Pod) error {
return err
}
// Read counter data files.
// A map to store counter data, indexed by pkgid/fnid tuple.
pmm := make(map[pkfunc][]uint32)
for _, cdf := range p.CounterDataFiles {
// Helper to read a single counter data file.
readcdf := func(cdf string) error {
cf, err := os.Open(cdf)
if err != nil {
return fmt.Errorf("opening counter data file %s: %s", cdf, err)
}
defer cf.Close()
var cdr *decodecounter.CounterDataReader
cdr, err = decodecounter.NewCounterDataReader(cdf, cf)
if err != nil {
@ -170,6 +173,14 @@ func (ts *tstate) processPod(p pods.Pod) error {
copy(c, data.Counters)
pmm[key] = c
}
return nil
}
// Read counter data files.
for _, cdf := range p.CounterDataFiles {
if err := readcdf(cdf); err != nil {
return err
}
}
// Visit meta-data file.