From 0f1251ebdef2a54743be1506b4e02d269ac3346f Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Thu, 9 Feb 2023 09:38:24 +0100 Subject: [PATCH] Dispose previous response in Webcmdlets (#19117) --- .../utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index c231aeac5a..bd4e762f5a 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -1274,6 +1274,7 @@ namespace Microsoft.PowerShell.Commands // Continue to handle redirection using HttpRequestMessage redirectRequest = GetRequest(currentUri); + response.Dispose(); response = GetResponse(client, redirectRequest, handleRedirect); } @@ -1308,7 +1309,8 @@ namespace Microsoft.PowerShell.Commands WriteVerbose(reqVerboseMsg); - return GetResponse(client, requestWithoutRange, handleRedirect); + response.Dispose(); + response = GetResponse(client, requestWithoutRange, handleRedirect); } } @@ -1421,7 +1423,7 @@ namespace Microsoft.PowerShell.Commands WriteVerbose(reqVerboseMsg); - HttpResponseMessage response = GetResponse(client, request, handleRedirect); + using HttpResponseMessage response = GetResponse(client, request, handleRedirect); string contentType = ContentHelper.GetContentType(response); string respVerboseMsg = string.Format(