internal/lockedfile: keep objects alive while stopping cleanups

Fixes https://go.dev/issues/74780.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-02-18 20:00:32 +09:00
parent 149dfbb6af
commit 3bfe99d3d8
2 changed files with 5 additions and 8 deletions

View File

@@ -94,6 +94,11 @@ func (f *File) Close() error {
err := closeFile(f.osFile.File)
f.cleanup.Stop()
// f may be dead at the moment after we access f.cleanup,
// so the cleanup can fire before Stop completes. Keep f
// alive while we call Stop. See the documentation for
// runtime.Cleanup.Stop.
runtime.KeepAlive(f)
return err
}