Fix exceptional resource leak CID18207

This commit is contained in:
_aLfa_ 2014-09-26 18:28:44 +02:00
parent 82eeb00413
commit 1020fe7b3f

View File

@ -378,13 +378,13 @@ namespace Nikse.SubtitleEdit.Forms
public static Encoding GetScreenScrapingEncoding(string languagePair)
{
WebClient webClient = null;
try
{
string url = String.Format("http://translate.google.com/?hl=en&eotf=1&sl={0}&tl={1}&q={2}", languagePair.Substring(0, 2), languagePair.Substring(3), "123 456");
var webClient = new WebClient();
webClient = new WebClient();
webClient.Proxy = Utilities.GetProxy();
string result = webClient.DownloadString(url).ToLower();
webClient.Dispose();
int idx = result.IndexOf("charset", StringComparison.Ordinal);
int end = result.IndexOf('"', idx + 8);
string charset = result.Substring(idx, end - idx).Replace("charset=", string.Empty);
@ -394,6 +394,13 @@ namespace Nikse.SubtitleEdit.Forms
{
return Encoding.Default;
}
finally
{
if (webClient != null)
{
webClient.Dispose();
}
}
}
/// <summary>