Examples of errors detected by the V3114 diagnostic
V3114. IDisposable object is not disposed before method returns.
AWS SDK for .NET
V3114 IDisposable object 'rsa' is not disposed before method returns. GetPasswordDataResponse.Extensions.cs 48
public string GetDecryptedPassword(string rsaPrivateKey)
{
RSAParameters rsaParams;
try
{
rsaParams = new PemReader(
new StringReader(rsaPrivateKey.Trim())
).ReadPrivatekey();
}
catch (Exception e)
{
throw new AmazonEC2Exception("Invalid RSA Private Key", e);
}
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); // <=
rsa.ImportParameters(rsaParams);
byte[] encryptedBytes = Convert.FromBase64String(this.PasswordData);
var decryptedBytes = rsa.Decrypt(encryptedBytes, false);
string decrypted = Encoding.UTF8.GetString(decryptedBytes);
return decrypted;
}