From cd4a2ee242456cbdab307445add030f5f78038fb Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sat, 11 Apr 2026 18:05:10 -0300 Subject: [PATCH] HttpResponseMessage Never Disposed in Multiple Locations (M9 fix) --- Knossos.NET/Classes/KnUtils.cs | 2 +- Knossos.NET/Models/GitHubApi.cs | 2 +- Knossos.NET/Models/Nebula.cs | 2 +- Knossos.NET/ViewModels/CommunityViewModel.cs | 2 +- Knossos.NET/ViewModels/PxoViewModel.cs | 2 +- Knossos.NET/ViewModels/Templates/DebugFiltersViewModel.cs | 2 +- Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs | 6 +++--- Knossos.NET/ViewModels/Templates/DevToolManagerViewModel.cs | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Knossos.NET/Classes/KnUtils.cs b/Knossos.NET/Classes/KnUtils.cs index 6c25c9c0..f1bd1a1d 100644 --- a/Knossos.NET/Classes/KnUtils.cs +++ b/Knossos.NET/Classes/KnUtils.cs @@ -808,7 +808,7 @@ public static string GetCachePath() string? newEtag = null; Log.Add(Log.LogSeverity.Information, "KnUtils.GetUrlFileEtag()", "Getting " + url + " etag."); - var result = await KnUtils.GetHttpClient().GetAsync(url, HttpCompletionOption.ResponseHeadersRead); + using var result = await KnUtils.GetHttpClient().GetAsync(url, HttpCompletionOption.ResponseHeadersRead); newEtag = result.Headers?.ETag?.ToString().Replace("\"", ""); try { diff --git a/Knossos.NET/Models/GitHubApi.cs b/Knossos.NET/Models/GitHubApi.cs index a7222af9..e9bc2470 100644 --- a/Knossos.NET/Models/GitHubApi.cs +++ b/Knossos.NET/Models/GitHubApi.cs @@ -19,7 +19,7 @@ public static class GitHubApi { var client = KnUtils.GetHttpClient(); client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("product", "1")); - HttpResponseMessage response = await client.GetAsync(Knossos.GitHubUpdateRepoURL + "/releases/latest"); + using var response = await client.GetAsync(Knossos.GitHubUpdateRepoURL + "/releases/latest"); var json = await response.Content.ReadAsStringAsync(); return JsonSerializer.Deserialize(json)!; } diff --git a/Knossos.NET/Models/Nebula.cs b/Knossos.NET/Models/Nebula.cs index accd5dbf..da984747 100644 --- a/Knossos.NET/Models/Nebula.cs +++ b/Knossos.NET/Models/Nebula.cs @@ -196,7 +196,7 @@ public static async Task Trinity() { try { - HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync(ModTagsURL).ConfigureAwait(false); + using var response = await KnUtils.GetHttpClient().GetAsync(ModTagsURL).ConfigureAwait(false); var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var tagsRepo = JsonSerializer.Deserialize(json)!; if (tagsRepo != null) diff --git a/Knossos.NET/ViewModels/CommunityViewModel.cs b/Knossos.NET/ViewModels/CommunityViewModel.cs index c36083c8..761e9362 100644 --- a/Knossos.NET/ViewModels/CommunityViewModel.cs +++ b/Knossos.NET/ViewModels/CommunityViewModel.cs @@ -30,7 +30,7 @@ public async Task LoadFAQRepo() try { - HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync(Knossos.FAQURL).ConfigureAwait(false); + using var response = await KnUtils.GetHttpClient().GetAsync(Knossos.FAQURL).ConfigureAwait(false); var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var faqRepo = JsonSerializer.Deserialize(json)!; if(faqRepo != null) diff --git a/Knossos.NET/ViewModels/PxoViewModel.cs b/Knossos.NET/ViewModels/PxoViewModel.cs index e127f7ce..2d096e16 100644 --- a/Knossos.NET/ViewModels/PxoViewModel.cs +++ b/Knossos.NET/ViewModels/PxoViewModel.cs @@ -143,7 +143,7 @@ public async void RefreshData() { try { - HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync("https://pxo.nottheeye.com/api/v1/games/active").ConfigureAwait(false); + using var response = await KnUtils.GetHttpClient().GetAsync("https://pxo.nottheeye.com/api/v1/games/active").ConfigureAwait(false); var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); Dispatcher.UIThread.Invoke(() => { diff --git a/Knossos.NET/ViewModels/Templates/DebugFiltersViewModel.cs b/Knossos.NET/ViewModels/Templates/DebugFiltersViewModel.cs index 5da5a849..44f4ea7c 100644 --- a/Knossos.NET/ViewModels/Templates/DebugFiltersViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/DebugFiltersViewModel.cs @@ -36,7 +36,7 @@ public async Task LoadDebugRepo() try { - HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync(Knossos.debugFilterURL).ConfigureAwait(false); + using var response = await KnUtils.GetHttpClient().GetAsync(Knossos.debugFilterURL).ConfigureAwait(false); var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var debugRepo = JsonSerializer.Deserialize(json)!; if(debugRepo != null) diff --git a/Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs b/Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs index 6e913a07..a011275c 100644 --- a/Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs @@ -40,7 +40,7 @@ public DevModScreenshot(string modPath, string path, DevModDetailsViewModel deta else { Task.Run(async () => { - HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync(path).ConfigureAwait(false); + using var response = await KnUtils.GetHttpClient().GetAsync(path).ConfigureAwait(false); byte[] content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); using (Stream stream = new MemoryStream(content)) { @@ -322,7 +322,7 @@ private void LoadBannerImage() { Task.Run(async () => { - HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync(TileImagePath).ConfigureAwait(false); + using var response = await KnUtils.GetHttpClient().GetAsync(TileImagePath).ConfigureAwait(false); byte[] content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); using (Stream stream = new MemoryStream(content)) { @@ -354,7 +354,7 @@ private void LoadTileImage() else { Task.Run( async () => { - HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync(TileImagePath).ConfigureAwait(false); + using var response = await KnUtils.GetHttpClient().GetAsync(TileImagePath).ConfigureAwait(false); byte[] content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); using (Stream stream = new MemoryStream(content)) { diff --git a/Knossos.NET/ViewModels/Templates/DevToolManagerViewModel.cs b/Knossos.NET/ViewModels/Templates/DevToolManagerViewModel.cs index 60ae4c60..f49d33bd 100644 --- a/Knossos.NET/ViewModels/Templates/DevToolManagerViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/DevToolManagerViewModel.cs @@ -197,7 +197,7 @@ private async Task LoadToolRepo() { try { - HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync(Knossos.ToolRepoURL).ConfigureAwait(false); + using var response = await KnUtils.GetHttpClient().GetAsync(Knossos.ToolRepoURL).ConfigureAwait(false); var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var toolsRepo = JsonSerializer.Deserialize(json)!; if(toolsRepo != null && toolsRepo.Any())