Description
This code generates S3966 erroneously detecting f has already been disposed in the 'finally' block and not realising a new instance was assigned in the 'if'.
Reproducer
public class Foo : IDisposable
{
public void Dispose()
{
}
public static void Bar(bool x)
{
var f = new Foo();
try
{
if (x)
{
f.Dispose();
f = new Foo();
}
}
finally
{
f.Dispose();
}
}
}
Product and Version
SonarAnalyzer.CSharp Version 10.17.0.131074
Description
This code generates S3966 erroneously detecting f has already been disposed in the 'finally' block and not realising a new instance was assigned in the 'if'.
Reproducer
Product and Version
SonarAnalyzer.CSharp Version 10.17.0.131074