File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -72,21 +72,23 @@ extension _BodyStreamSource : _BodySource {
72
72
}
73
73
74
74
let buffer = UnsafeMutableRawBufferPointer . allocate ( byteCount: length, alignment: MemoryLayout< UInt8> . alignment)
75
- defer { buffer. deallocate ( ) }
76
75
77
76
guard let pointer = buffer. baseAddress? . assumingMemoryBound ( to: UInt8 . self) else {
77
+ buffer. deallocate ( )
78
78
return . error
79
79
}
80
80
81
81
let readBytes = self . inputStream. read ( pointer, maxLength: length)
82
82
if readBytes > 0 {
83
- let dispatchData = DispatchData ( bytes : UnsafeRawBufferPointer ( buffer) )
83
+ let dispatchData = DispatchData ( bytesNoCopy : UnsafeRawBufferPointer ( buffer) , deallocator : . custom ( nil , { buffer . deallocate ( ) } ) )
84
84
return . data( dispatchData. subdata ( in: 0 ..< readBytes) )
85
85
}
86
86
else if readBytes == 0 {
87
+ buffer. deallocate ( )
87
88
return . done
88
89
}
89
90
else {
91
+ buffer. deallocate ( )
90
92
return . error
91
93
}
92
94
}
You can’t perform that action at this time.
0 commit comments