Dispose IDisposable instances (#15810)
This commit is contained in:
@@ -51,7 +51,7 @@ public class ExcessiveHeadersCheck : HealthCheck
|
||||
var url = _hostingEnvironment.ApplicationMainUrl?.GetLeftPart(UriPartial.Authority);
|
||||
|
||||
// Access the site home page and check for the headers
|
||||
var request = new HttpRequestMessage(HttpMethod.Head, url);
|
||||
using var request = new HttpRequestMessage(HttpMethod.Head, url);
|
||||
try
|
||||
{
|
||||
using HttpResponseMessage response = await HttpClient.SendAsync(request);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class HttpsCheck : HealthCheck
|
||||
var urlBuilder = new UriBuilder(_hostingEnvironment.ApplicationMainUrl) { Scheme = Uri.UriSchemeHttps };
|
||||
Uri url = urlBuilder.Uri;
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Head, url);
|
||||
using var request = new HttpRequestMessage(HttpMethod.Head, url);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ public abstract class OEmbedProviderBase : IEmbedProvider
|
||||
|
||||
using (var request = new HttpRequestMessage(HttpMethod.Get, url))
|
||||
{
|
||||
HttpResponseMessage response = _httpClient.SendAsync(request).GetAwaiter().GetResult();
|
||||
using HttpResponseMessage response = _httpClient.SendAsync(request).GetAwaiter().GetResult();
|
||||
return response.Content.ReadAsStringAsync().Result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class InstallationRepository : IInstallationRepository
|
||||
_httpClient = new HttpClient();
|
||||
}
|
||||
|
||||
var content = new StringContent(_jsonSerializer.Serialize(installLog), Encoding.UTF8, "application/json");
|
||||
using var content = new StringContent(_jsonSerializer.Serialize(installLog), Encoding.UTF8, "application/json");
|
||||
|
||||
await _httpClient.PostAsync(RestApiInstallUrl, content);
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ public class UpgradeCheckRepository : IUpgradeCheckRepository
|
||||
_httpClient = new HttpClient();
|
||||
}
|
||||
|
||||
var content = new StringContent(_jsonSerializer.Serialize(new CheckUpgradeDto(version)), Encoding.UTF8, "application/json");
|
||||
using var content = new StringContent(_jsonSerializer.Serialize(new CheckUpgradeDto(version)), Encoding.UTF8, "application/json");
|
||||
|
||||
_httpClient.Timeout = TimeSpan.FromSeconds(1);
|
||||
HttpResponseMessage task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, content);
|
||||
using HttpResponseMessage task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, content);
|
||||
var json = await task.Content.ReadAsStringAsync();
|
||||
UpgradeResult? result = _jsonSerializer.Deserialize<UpgradeResult>(json);
|
||||
|
||||
|
||||
@@ -16,8 +16,11 @@ public class LegacyPasswordSecurity
|
||||
public static string GenerateSalt()
|
||||
{
|
||||
var numArray = new byte[16];
|
||||
new RNGCryptoServiceProvider().GetBytes(numArray);
|
||||
return Convert.ToBase64String(numArray);
|
||||
using (var rng = new RNGCryptoServiceProvider())
|
||||
{
|
||||
rng.GetBytes(numArray);
|
||||
return Convert.ToBase64String(numArray);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove v11
|
||||
@@ -86,7 +89,7 @@ public class LegacyPasswordSecurity
|
||||
/// </summary>
|
||||
public bool VerifyLegacyHashedPassword(string password, string dbPassword)
|
||||
{
|
||||
var hashAlgorithm = new HMACSHA1
|
||||
using var hashAlgorithm = new HMACSHA1
|
||||
{
|
||||
// the legacy salt was actually the password :(
|
||||
Key = Encoding.Unicode.GetBytes(password),
|
||||
|
||||
@@ -98,7 +98,10 @@ public class PasswordGenerator
|
||||
var data = new byte[length];
|
||||
var chArray = new char[length];
|
||||
var num1 = 0;
|
||||
new RNGCryptoServiceProvider().GetBytes(data);
|
||||
using (var rng = new RNGCryptoServiceProvider())
|
||||
{
|
||||
rng.GetBytes(data);
|
||||
}
|
||||
|
||||
for (var index = 0; index < length; ++index)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user