Skip to content

Commit

Permalink
Dev: fix memory leak in _HTTPBodyStreamSource
Browse files Browse the repository at this point in the history
andriydruk committed Nov 16, 2018
1 parent e99b969 commit c577fda
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Foundation/URLSession/http/HTTPBodySource.swift
Original file line number Diff line number Diff line change
@@ -130,13 +130,15 @@ extension _HTTPBodyStreamSource: _HTTPBodySource {
}
let readBytes = self.inputStream.read(pointer, maxLength: length)
if readBytes > 0 {
let dispatchData = DispatchData(bytes: UnsafeRawBufferPointer(buffer))
let dispatchData = DispatchData(bytesNoCopy: UnsafeRawBufferPointer(buffer), deallocator: .free)
return .data(dispatchData.subdata(in: 0 ..< readBytes))
}
else if readBytes == 0 {
buffer.deallocate()
return .done
}
else {
buffer.deallocate()
return .error
}
}

0 comments on commit c577fda

Please sign in to comment.