Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions S7.Net/Helper/MemoryStreamExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ public static void Write(this MemoryStream stream, ReadOnlySpan<byte> value)
{
byte[] buffer = ArrayPool<byte>.Shared.Rent(value.Length);

value.CopyTo(buffer);
stream.Write(buffer, 0, value.Length);

ArrayPool<byte>.Shared.Return(buffer);
try
{
value.CopyTo(buffer);
stream.Write(buffer, 0, value.Length);
}
finally
{
ArrayPool<byte>.Shared.Return(buffer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try-finally is actually not what one wants here. See dotnet/runtime#48257 (reply in thread) and the following comments.

Thanks for trying to address a problem anyway!
But I'd recommend to close this PR due the reasons mentioned in the link above.

}
}
}
#endif
Expand Down