Skip to content

Commit 6635316

Browse files
committed
internal/counter: avoid nil check panic
Some tests in this package attempt to close/unmmap files by calling a test helper function 'close'. When telemetry is off, mapped file, not the file, can be nil. Actually, the file argument (f) of close is never nil. Updates golang/go#60967 Change-Id: I4ca3feb233ede3a6512a4f3d50460c2fb28a6559 Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/505720 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]>
1 parent 4221be3 commit 6635316

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

internal/counter/counter_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ func TestBasic(t *testing.T) {
7878
// this is needed in Windows so that the generated testing.go file
7979
// can clean up the temporary test directory
8080
func close(f *file) {
81-
if f == nil {
81+
mf := f.current.Load()
82+
if mf == nil {
8283
// telemetry might have been off
8384
return
8485
}
85-
f.current.Load().f.Close()
86-
mmap.Munmap(f.current.Load().mapping)
86+
mmap.Munmap(mf.mapping)
87+
mf.f.Close()
8788
}
8889

8990
func TestLarge(t *testing.T) {

0 commit comments

Comments
 (0)