16
16
import csharp
17
17
import Dispose
18
18
import semmle.code.csharp.frameworks.System
19
+ import semmle.code.csharp.frameworks.system.threading.Tasks
19
20
import semmle.code.csharp.commons.Disposal
20
21
21
22
private class ReturnNode extends DataFlow:: ExprNode {
@@ -24,15 +25,27 @@ private class ReturnNode extends DataFlow::ExprNode {
24
25
}
25
26
}
26
27
28
+ private class Task extends Type {
29
+ Task ( ) {
30
+ this instanceof SystemThreadingTasksTaskClass or
31
+ this instanceof SystemThreadingTasksTaskTClass
32
+ }
33
+ }
34
+
27
35
module DisposeCallOnLocalIDisposableConfig implements DataFlow:: ConfigSig {
28
36
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
+ )
36
49
}
37
50
38
51
predicate isSink ( DataFlow:: Node node ) {
0 commit comments