File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
test/query-tests/API Abuse/DisposeNotCalledOnException Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -52,11 +52,19 @@ private class DisposeCall extends MethodCall {
5252 DisposeCall ( ) { this .getTarget ( ) instanceof DisposeMethod }
5353}
5454
55+ private predicate localFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
56+ DataFlow:: localFlowStep ( nodeFrom , nodeTo ) and
57+ not exists ( AssignableDefinition def , UsingStmt uds |
58+ nodeTo .asExpr ( ) = def .getAReachableRead ( ) and
59+ def .getTargetAccess ( ) = uds .getAVariableDeclExpr ( ) .getAccess ( )
60+ )
61+ }
62+
5563private predicate reachesDisposeCall ( DisposeCall disposeCall , DataFlow:: Node node ) {
56- DataFlow :: localFlowStep ( node , DataFlow:: exprNode ( disposeCall .getQualifier ( ) ) )
64+ localFlowStep ( node , DataFlow:: exprNode ( disposeCall .getQualifier ( ) ) )
5765 or
5866 exists ( DataFlow:: Node mid | reachesDisposeCall ( disposeCall , mid ) |
59- DataFlow :: localFlowStep ( node , mid )
67+ localFlowStep ( node , mid )
6068 )
6169}
6270
Original file line number Diff line number Diff line change @@ -62,6 +62,18 @@ public void Method()
6262 // GOOD: using declaration
6363 using SqlConnection c2 = new SqlConnection ( "" ) ;
6464 c2 . Open ( ) ;
65+
66+ // GOOD: Always disposed
67+ using SqlConnection c3 = new SqlConnection ( "" ) ;
68+ Throw2 ( c3 ) ;
69+ c3 . Dispose ( ) ;
70+
71+ // GOOD: Disposed automatically
72+ using ( SqlConnection c4 = new SqlConnection ( "" ) )
73+ {
74+ Throw2 ( c4 ) ;
75+ c4 . Dispose ( ) ;
76+ }
6577 }
6678
6779 void Throw1 ( SqlConnection sc )
You can’t perform that action at this time.
0 commit comments