microsoft / infersharp

Infer# is an interprocedural and scalable static code analyzer for C#. Via the capabilities of Facebook's Infer, this tool detects null dereferences, resource leaks, and thread-safety violations. It also performs taint flow tracking to detect critical security vulnerabilities like SQL injections.
MIT License
727 stars 29 forks source link

Call Class Dispose Instead of IDisposable Dispose #164

Closed matjin closed 1 year ago

matjin commented 1 year ago

The "using" construct in C# yields bytecode that invokes IDisposable.Dispose() rather than the instance's corresponding method. This can create issues when this method is for a user-defined IDisposable class, with a corresponding custom Dispose method, as then the spec for this method would fail to be applied. To fix this, we make sure that in such instances we invoke the instance's Dispose method.

xi-liu-ds commented 1 year ago

Overall it looks OK. I would suggest to create a unit test for this PR, with a resource in custom type allocated in the using statement.

matjin commented 1 year ago

Overall it looks OK. I would suggest to create a unit test for this PR, with a resource in custom type allocated in the using statement.

As discussed offline, I will go back and redo the test cases: the "Examples" solution should be our validation set for all of our pulse-based analysis.

matjin commented 1 year ago

image I have already prepared the test case I will add later.

This work will happen around when we go back and fix the nested using/translation of ldftn.