Skip to content

Commit

Permalink
Help checklocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Dec 16, 2024
1 parent e32d840 commit 7e23100
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions vfs/shm_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 {
Expand Down

0 comments on commit 7e23100

Please sign in to comment.