File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -68,16 +68,11 @@ func (s *vfsShm) Close() error {
68
68
panic (util .AssertErr ())
69
69
}
70
70
71
- func (s * vfsShm ) shmOpen () _ErrorCode {
71
+ func (s * vfsShm ) shmOpen () ( rc _ErrorCode ) {
72
72
if s .vfsShmParent != nil {
73
73
return _OK
74
74
}
75
75
76
- var f * os.File
77
- // Close file on error.
78
- // Keep this here to avoid confusing checklocks.
79
- defer func () { f .Close () }()
80
-
81
76
vfsShmListMtx .Lock ()
82
77
defer vfsShmListMtx .Unlock ()
83
78
@@ -98,11 +93,16 @@ func (s *vfsShm) shmOpen() _ErrorCode {
98
93
}
99
94
100
95
// Always open file read-write, as it will be shared.
101
- f , err = os .OpenFile (s .path ,
96
+ f , err : = os .OpenFile (s .path ,
102
97
os .O_RDWR | os .O_CREATE | _O_NOFOLLOW , 0666 )
103
98
if err != nil {
104
99
return _CANTOPEN
105
100
}
101
+ defer func () {
102
+ if rc != _OK {
103
+ f .Close ()
104
+ }
105
+ }()
106
106
107
107
// Dead man's switch.
108
108
if lock , rc := osTestLock (f , _SHM_DMS , 1 ); rc != _OK {
@@ -131,7 +131,6 @@ func (s *vfsShm) shmOpen() _ErrorCode {
131
131
File : f ,
132
132
info : fi ,
133
133
}
134
- f = nil // Don't close the file.
135
134
for i , g := range vfsShmList {
136
135
if g == nil {
137
136
vfsShmList [i ] = s .vfsShmParent
You can’t perform that action at this time.
0 commit comments