Skip to content

Commit 15b9457

Browse files
committed
Tweak.
1 parent 2555724 commit 15b9457

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

vfs/shm_bsd.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,11 @@ func (s *vfsShm) Close() error {
6868
panic(util.AssertErr())
6969
}
7070

71-
func (s *vfsShm) shmOpen() _ErrorCode {
71+
func (s *vfsShm) shmOpen() (rc _ErrorCode) {
7272
if s.vfsShmParent != nil {
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-
8176
vfsShmListMtx.Lock()
8277
defer vfsShmListMtx.Unlock()
8378

@@ -98,11 +93,16 @@ func (s *vfsShm) shmOpen() _ErrorCode {
9893
}
9994

10095
// Always open file read-write, as it will be shared.
101-
f, err = os.OpenFile(s.path,
96+
f, err := os.OpenFile(s.path,
10297
os.O_RDWR|os.O_CREATE|_O_NOFOLLOW, 0666)
10398
if err != nil {
10499
return _CANTOPEN
105100
}
101+
defer func() {
102+
if rc != _OK {
103+
f.Close()
104+
}
105+
}()
106106

107107
// Dead man's switch.
108108
if lock, rc := osTestLock(f, _SHM_DMS, 1); rc != _OK {
@@ -131,7 +131,6 @@ func (s *vfsShm) shmOpen() _ErrorCode {
131131
File: f,
132132
info: fi,
133133
}
134-
f = nil // Don't close the file.
135134
for i, g := range vfsShmList {
136135
if g == nil {
137136
vfsShmList[i] = s.vfsShmParent

0 commit comments

Comments
 (0)