Skip to content

Commit

Permalink
Make curl requests free-er
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Jan 21, 2024
1 parent 474154c commit 027e5ac
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions TwitchDownloaderCore/Tools/CurlImpersonate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,10 @@ public static byte[] GetCurlResponseBytes(string url)
{
var length = (int)size * (int)nmemb;

var buffer = ArrayPool<byte>.Shared.Rent(length);
try
unsafe
{
Marshal.Copy(data, buffer, 0, length);
stream.Write(buffer, 0, length);
}
finally
{
Array.Clear(buffer); // Clear the buffer in case we were working with sensitive information.
ArrayPool<byte>.Shared.Return(buffer);
using var ums = new UnmanagedMemoryStream((byte*)data, length);
ums.CopyTo(stream);
}

return (UIntPtr)length;
Expand Down

0 comments on commit 027e5ac

Please sign in to comment.