From: Than McIntosh Date: Wed, 21 Dec 2022 16:03:16 +0000 (-0500) Subject: runtime/coverage: add missing file close in test support helper X-Git-Tag: go1.20rc2~1^2~12 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fadd77c05b0f6633d753da61c74a7ed81959b252;p=gostls13.git 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 Run-TryBot: Than McIntosh TryBot-Result: Gopher Robot --- diff --git a/src/runtime/coverage/testsupport.go b/src/runtime/coverage/testsupport.go index 462d06c878..1d90ebd7a2 100644 --- a/src/runtime/coverage/testsupport.go +++ b/src/runtime/coverage/testsupport.go @@ -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.