@@ -6,32 +6,32 @@ import codeql.util.Boolean
66
77/**
88 * A library for detecting leaked resources.
9- *
9+ *
1010 * To use this library, implement `ResourceLeakConfigSig`:
11- *
11+ *
1212 * ```
1313 * class UnjoinedThreadConfig implements ResourceLeakConfigSig {
1414 * predicate isResource(DataFlow::Node node) {
1515 * node.asExpr().isThreadCreate()
1616 * }
17- *
17+ *
1818 * predicate isFree(ControlFlowNode node, DataFlow::Node resource) {
1919 * node.asExpr().isThreadJoin(resource.asExpr())
2020 * }
2121 * }
2222 * ```
23- *
23+ *
2424 * You can now check if a resource is leaked through the module predicate
2525 * `ResourceLeak<UnjoinedThreadConfig>::isLeaked(resource)`.
26- *
26+ *
2727 * The leak analysis finds the exit point of the function in which the resource is is declared, and
2828 * then reverses execution from there using `getAPredecessor()`. When this backwards walk discovers
2929 * a control flow node that frees the resource, that exploration stops. If any exploration reaches
3030 * a resource, that resource may be leaked via that path.
31- *
31+ *
3232 * Uses `DataFlow::Node` in order to track aliases of the resource to better detect when the
3333 * resource is freed.
34- *
34+ *
3535 * This library by default assumes that resources are expression nodes. To use it with other kinds
3636 * of nodes requires overriding `resourceInitPoint`.
3737 */
@@ -41,7 +41,8 @@ signature module ResourceLeakConfigSig {
4141 predicate isFree ( ControlFlowNode node , DataFlow:: Node resource ) ;
4242
4343 default DataFlow:: Node getAnAlias ( DataFlow:: Node node ) {
44- DataFlow:: localFlow ( node , result ) or
44+ DataFlow:: localFlow ( node , result )
45+ or
4546 exists ( Expr current , Expr after |
4647 current in [ node .asExpr ( ) , node .asDefiningArgument ( ) ] and
4748 after in [ result .asExpr ( ) , result .asDefiningArgument ( ) ] and
@@ -57,9 +58,10 @@ signature module ResourceLeakConfigSig {
5758}
5859
5960module 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+ }
6365
6466 /**
6567 * Get an alias of a resource, and aliases of nodes that are aliased by a resource.
@@ -98,4 +100,4 @@ module ResourceLeak<ResourceLeakConfigSig Config> {
98100 isLeakedAtControlPoint ( resourceWrapper , result )
99101 )
100102 }
101- }
103+ }
0 commit comments