1616import csharp
1717import Dispose
1818import semmle.code.csharp.frameworks.System
19+ import semmle.code.csharp.frameworks.system.threading.Tasks
1920import semmle.code.csharp.commons.Disposal
2021
2122private class ReturnNode extends DataFlow:: ExprNode {
@@ -24,15 +25,27 @@ private class ReturnNode extends DataFlow::ExprNode {
2425 }
2526}
2627
28+ private class Task extends Type {
29+ Task ( ) {
30+ this instanceof SystemThreadingTasksTaskClass or
31+ this instanceof SystemThreadingTasksTaskTClass
32+ }
33+ }
34+
2735module DisposeCallOnLocalIDisposableConfig implements DataFlow:: ConfigSig {
2836 predicate isSource ( DataFlow:: Node node ) {
29- node .asExpr ( ) =
30- any ( LocalScopeDisposableCreation disposable |
31- // Only care about library types - user types often have spurious IDisposable declarations
32- disposable .getType ( ) .fromLibrary ( ) and
33- // WebControls are usually disposed automatically
34- not disposable .getType ( ) instanceof WebControl
35- )
37+ exists ( LocalScopeDisposableCreation disposable , Type t |
38+ node .asExpr ( ) = disposable and
39+ t = disposable .getType ( )
40+ |
41+ // Only care about library types - user types often have spurious IDisposable declarations
42+ t .fromLibrary ( ) and
43+ // WebControls are usually disposed automatically
44+ not t instanceof WebControl and
45+ // It is typically not nessesary to dispose tasks
46+ // https://devblogs.microsoft.com/pfxteam/do-i-need-to-dispose-of-tasks/
47+ not t instanceof Task
48+ )
3649 }
3750
3851 predicate isSink ( DataFlow:: Node node ) {
0 commit comments