File tree Expand file tree Collapse file tree 2 files changed +8
-23
lines changed Expand file tree Collapse file tree 2 files changed +8
-23
lines changed Original file line number Diff line number Diff line change @@ -632,26 +632,7 @@ internal struct TrackedFileDescriptor: ~Copyable {
632
632
return
633
633
}
634
634
635
- do {
636
- try fileDescriptor. close ( )
637
- } catch {
638
- guard let errno: Errno = error as? Errno else {
639
- return
640
- }
641
- // Getting `.badFileDescriptor` suggests that the file descriptor
642
- // might have been closed unexpectedly. This can pose security risks
643
- // if another part of the code inadvertently reuses the same file descriptor
644
- // number. This problem is especially concerning on Unix systems due to POSIX’s
645
- // guarantee of using the lowest available file descriptor number, making reuse
646
- // more probable. We use `fatalError` upon receiving `.badFileDescriptor`
647
- // to prevent accidentally closing a different file descriptor.
648
- guard errno != . badFileDescriptor else {
649
- fatalError (
650
- " FileDescriptor \( fileDescriptor. rawValue) is already closed "
651
- )
652
- }
653
- // Otherwise ignore the error
654
- }
635
+ fatalError ( " FileDescriptor \( self . fileDescriptor. rawValue) was not closed " )
655
636
}
656
637
657
638
internal func platformDescriptor( ) -> PlatformFileDescriptor {
@@ -695,7 +676,7 @@ internal struct TrackedDispatchIO: ~Copyable {
695
676
return
696
677
}
697
678
698
- dispatchIO . close ( )
679
+ fatalError ( " DispatchIO \( self . dispatchIO ) was not closed " )
699
680
}
700
681
}
701
682
#endif
Original file line number Diff line number Diff line change @@ -143,9 +143,12 @@ public struct BytesOutput: OutputProtocol {
143
143
from diskIO: consuming TrackedPlatformDiskIO ?
144
144
) async throws -> [ UInt8 ] {
145
145
#if os(Windows)
146
- return try await diskIO? . fileDescriptor. read ( upToLength: self . maxSize) ?? [ ]
146
+ let result = try await diskIO? . fileDescriptor. read ( upToLength: self . maxSize) ?? [ ]
147
+ try diskIO? . safelyClose ( )
148
+ return result
147
149
#else
148
150
let result = try await diskIO!. dispatchIO. read ( upToLength: self . maxSize)
151
+ try diskIO? . safelyClose ( )
149
152
return result? . array ( ) ?? [ ]
150
153
#endif
151
154
}
@@ -261,12 +264,13 @@ extension OutputProtocol {
261
264
if OutputType . self == Void . self {
262
265
return ( ) as! OutputType
263
266
}
264
-
265
267
#if os(Windows)
266
268
let result = try await diskIO? . fileDescriptor. read ( upToLength: self . maxSize)
269
+ try diskIO? . safelyClose ( )
267
270
return try self . output ( from: result ?? [ ] )
268
271
#else
269
272
let result = try await diskIO!. dispatchIO. read ( upToLength: self . maxSize)
273
+ try diskIO? . safelyClose ( )
270
274
return try self . output ( from: result ?? . empty)
271
275
#endif
272
276
}
You can’t perform that action at this time.
0 commit comments