Skip to content

Commit c577fda

Browse files
committed
Dev: fix memory leak in _HTTPBodyStreamSource
1 parent e99b969 commit c577fda

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Foundation/URLSession/http/HTTPBodySource.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ extension _HTTPBodyStreamSource: _HTTPBodySource {
130130
}
131131
let readBytes = self.inputStream.read(pointer, maxLength: length)
132132
if readBytes > 0 {
133-
let dispatchData = DispatchData(bytes: UnsafeRawBufferPointer(buffer))
133+
let dispatchData = DispatchData(bytesNoCopy: UnsafeRawBufferPointer(buffer), deallocator: .free)
134134
return .data(dispatchData.subdata(in: 0 ..< readBytes))
135135
}
136136
else if readBytes == 0 {
137+
buffer.deallocate()
137138
return .done
138139
}
139140
else {
141+
buffer.deallocate()
140142
return .error
141143
}
142144
}

0 commit comments

Comments
 (0)