@@ -6,32 +6,32 @@ import codeql.util.Boolean
6
6
7
7
/**
8
8
* A library for detecting leaked resources.
9
- *
9
+ *
10
10
* To use this library, implement `ResourceLeakConfigSig`:
11
- *
11
+ *
12
12
* ```
13
13
* class UnjoinedThreadConfig implements ResourceLeakConfigSig {
14
14
* predicate isResource(DataFlow::Node node) {
15
15
* node.asExpr().isThreadCreate()
16
16
* }
17
- *
17
+ *
18
18
* predicate isFree(ControlFlowNode node, DataFlow::Node resource) {
19
19
* node.asExpr().isThreadJoin(resource.asExpr())
20
20
* }
21
21
* }
22
22
* ```
23
- *
23
+ *
24
24
* You can now check if a resource is leaked through the module predicate
25
25
* `ResourceLeak<UnjoinedThreadConfig>::isLeaked(resource)`.
26
- *
26
+ *
27
27
* The leak analysis finds the exit point of the function in which the resource is is declared, and
28
28
* then reverses execution from there using `getAPredecessor()`. When this backwards walk discovers
29
29
* a control flow node that frees the resource, that exploration stops. If any exploration reaches
30
30
* a resource, that resource may be leaked via that path.
31
- *
31
+ *
32
32
* Uses `DataFlow::Node` in order to track aliases of the resource to better detect when the
33
33
* resource is freed.
34
- *
34
+ *
35
35
* This library by default assumes that resources are expression nodes. To use it with other kinds
36
36
* of nodes requires overriding `resourceInitPoint`.
37
37
*/
@@ -41,7 +41,8 @@ signature module ResourceLeakConfigSig {
41
41
predicate isFree ( ControlFlowNode node , DataFlow:: Node resource ) ;
42
42
43
43
default DataFlow:: Node getAnAlias ( DataFlow:: Node node ) {
44
- DataFlow:: localFlow ( node , result ) or
44
+ DataFlow:: localFlow ( node , result )
45
+ or
45
46
exists ( Expr current , Expr after |
46
47
current in [ node .asExpr ( ) , node .asDefiningArgument ( ) ] and
47
48
after in [ result .asExpr ( ) , result .asDefiningArgument ( ) ] and
@@ -57,9 +58,10 @@ signature module ResourceLeakConfigSig {
57
58
}
58
59
59
60
module ResourceLeak< ResourceLeakConfigSig Config> {
60
- private newtype TResource = TJustResource ( DataFlow:: Node resource , ControlFlowNode cfgNode ) {
61
- Config:: isAllocate ( cfgNode , resource )
62
- }
61
+ private newtype TResource =
62
+ TJustResource ( DataFlow:: Node resource , ControlFlowNode cfgNode ) {
63
+ Config:: isAllocate ( cfgNode , resource )
64
+ }
63
65
64
66
/**
65
67
* Get an alias of a resource, and aliases of nodes that are aliased by a resource.
@@ -98,4 +100,4 @@ module ResourceLeak<ResourceLeakConfigSig Config> {
98
100
isLeakedAtControlPoint ( resourceWrapper , result )
99
101
)
100
102
}
101
- }
103
+ }
0 commit comments