From 7e23100ff7d2794c6ec491753a00e1a0a2b2be58 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 16 Dec 2024 13:42:41 +0000 Subject: [PATCH] Help checklocks. --- vfs/shm_bsd.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vfs/shm_bsd.go b/vfs/shm_bsd.go index d4c71e66..10d6dbf6 100644 --- a/vfs/shm_bsd.go +++ b/vfs/shm_bsd.go @@ -73,6 +73,11 @@ func (s *vfsShm) shmOpen() _ErrorCode { return _OK } + var f *os.File + // Close file on error. + // Keep this here to avoid confusing checklocks. + defer func() { f.Close() }() + vfsShmListMtx.Lock() defer vfsShmListMtx.Unlock() @@ -93,13 +98,11 @@ func (s *vfsShm) shmOpen() _ErrorCode { } // Always open file read-write, as it will be shared. - f, err := os.OpenFile(s.path, + f, err = os.OpenFile(s.path, os.O_RDWR|os.O_CREATE|_O_NOFOLLOW, 0666) if err != nil { return _CANTOPEN } - // Closes file if it's not nil. - defer func() { f.Close() }() // Dead man's switch. if lock, rc := osTestLock(f, _SHM_DMS, 1); rc != _OK {