aboutsummaryrefslogtreecommitdiff
path: root/src/os/file_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/file_windows.go')
-rw-r--r--src/os/file_windows.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/os/file_windows.go b/src/os/file_windows.go
index ee6735fe44..7e94328710 100644
--- a/src/os/file_windows.go
+++ b/src/os/file_windows.go
@@ -22,14 +22,13 @@ const _UTIME_OMIT = -1
// file is the real representation of *File.
// The extra level of indirection ensures that no clients of os
-// can overwrite this data, which could cause the cleanup
+// can overwrite this data, which could cause the finalizer
// to close the wrong file descriptor.
type file struct {
pfd poll.FD
name string
dirinfo atomic.Pointer[dirInfo] // nil unless directory being read
appendMode bool // whether file is opened for appending
- cleanup runtime.Cleanup // cleanup closes the file when no longer referenced
}
// fd is the Windows implementation of Fd.
@@ -69,7 +68,7 @@ func newFile(h syscall.Handle, name string, kind string, nonBlocking bool) *File
},
name: name,
}}
- f.cleanup = runtime.AddCleanup(f, func(f *file) { f.close() }, f.file)
+ runtime.SetFinalizer(f.file, (*file).close)
// Ignore initialization errors.
// Assume any problems will show up in later I/O.
@@ -144,9 +143,8 @@ func (file *file) close() error {
err = &PathError{Op: "close", Path: file.name, Err: e}
}
- // There is no need for a cleanup at this point. File must be alive at the point
- // where cleanup.stop is called.
- file.cleanup.Stop()
+ // no need for a finalizer anymore
+ runtime.SetFinalizer(file, nil)
return err
}