Skip to content

Commit 7e23100

Browse files
committed
Help checklocks.
1 parent e32d840 commit 7e23100

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

vfs/shm_bsd.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ func (s *vfsShm) shmOpen() _ErrorCode {
7373
return _OK
7474
}
7575

76+
var f *os.File
77+
// Close file on error.
78+
// Keep this here to avoid confusing checklocks.
79+
defer func() { f.Close() }()
80+
7681
vfsShmListMtx.Lock()
7782
defer vfsShmListMtx.Unlock()
7883

@@ -93,13 +98,11 @@ func (s *vfsShm) shmOpen() _ErrorCode {
9398
}
9499

95100
// Always open file read-write, as it will be shared.
96-
f, err := os.OpenFile(s.path,
101+
f, err = os.OpenFile(s.path,
97102
os.O_RDWR|os.O_CREATE|_O_NOFOLLOW, 0666)
98103
if err != nil {
99104
return _CANTOPEN
100105
}
101-
// Closes file if it's not nil.
102-
defer func() { f.Close() }()
103106

104107
// Dead man's switch.
105108
if lock, rc := osTestLock(f, _SHM_DMS, 1); rc != _OK {

0 commit comments

Comments
 (0)