From 58631d5d8a30d82f5b75241bfdd6a39b549da7dc Mon Sep 17 00:00:00 2001 From: fyr77 Date: Thu, 3 Sep 2020 22:24:22 +0200 Subject: [PATCH] fix potential memory leak --- EnvyUpdate/Util.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/EnvyUpdate/Util.cs b/EnvyUpdate/Util.cs index 015b6fd..2d0cdfc 100644 --- a/EnvyUpdate/Util.cs +++ b/EnvyUpdate/Util.cs @@ -108,12 +108,15 @@ namespace EnvyUpdate { // This will fetch the most recent version's tag on GitHub. string updPath = "https://api.github.com/repos/fyr77/envyupdate/releases/latest"; + dynamic data = null; - WebClient wc = new WebClient(); - // Use some user agent to not get 403'd by GitHub. - wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"); - string webData = wc.DownloadString(updPath); - dynamic data = JsonConvert.DeserializeObject(webData); + using (var wc = new WebClient()) + { + // Use some user agent to not get 403'd by GitHub. + wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"); + string webData = wc.DownloadString(updPath); + data = JsonConvert.DeserializeObject(webData); + } // I am not catching a possible parsing exception, because I cannot think of any way it could happen. // If there is no internet connection, it should already throw when using the web client.