@@ -18,18 +18,20 @@ import semmle.code.cpp.controlflow.LocalScopeVariableReachability
1818 */
1919predicate mayCallFunction ( Expr call , Function f ) {
2020 call .( FunctionCall ) .getTarget ( ) = f or
21- call .( VariableCall ) .getVariable ( ) .getAnAssignedValue ( ) .getAChild * ( ) . ( FunctionAccess ) . getTarget ( ) =
22- f
21+ call .( VariableCall ) .getVariable ( ) .getAnAssignedValue ( ) .
22+ getAChild * ( ) . ( FunctionAccess ) . getTarget ( ) = f
2323}
2424
2525predicate allocCallOrIndirect ( Expr e ) {
2626 // direct alloc call
2727 isAllocationExpr ( e ) and
28+
2829 // We are only interested in alloc calls that are
2930 // actually freed somehow, as MemoryNeverFreed
3031 // will catch those that aren't.
3132 allocMayBeFreed ( e )
3233 or
34+
3335 exists ( ReturnStmt rtn |
3436 // indirect alloc call
3537 mayCallFunction ( e , rtn .getEnclosingFunction ( ) ) and
@@ -62,6 +64,7 @@ predicate verifiedRealloc(FunctionCall reallocCall, Variable v, ControlFlowNode
6264 newV .getAnAssignedValue ( ) = reallocCall and
6365 node .( AnalysedExpr ) .getNonNullSuccessor ( newV ) = verified and
6466 // note: this case uses naive flow logic (getAnAssignedValue).
67+
6568 // special case: if the result of the 'realloc' is assigned to the
6669 // same variable, we don't descriminate properly between the old
6770 // and the new allocation; better to not consider this a free at
@@ -113,6 +116,7 @@ class AllocVariableReachability extends LocalScopeVariableReachabilityWithReassi
113116 exists ( node .( AnalysedExpr ) .getNullSuccessor ( v ) ) or
114117 freeCallOrIndirect ( node , v ) or
115118 assignedToFieldOrGlobal ( v , node ) or
119+
116120 // node may be used directly in query
117121 v .getFunction ( ) = node .( ReturnStmt ) .getEnclosingFunction ( )
118122 }
@@ -148,10 +152,12 @@ class AllocReachability extends LocalScopeVariableReachabilityExt {
148152 }
149153
150154 override predicate isBarrier (
151- ControlFlowNode source , ControlFlowNode node , ControlFlowNode next , LocalScopeVariable v
152- ) {
155+ ControlFlowNode source , ControlFlowNode node , ControlFlowNode next ,
156+ LocalScopeVariable v )
157+ {
153158 isSource ( source , v ) and
154159 next = node .getASuccessor ( ) and
160+
155161 // the memory (stored in any variable `v0`) allocated at `source` is freed or
156162 // assigned to a global at node, or NULL checked on the edge node -> next.
157163 exists ( LocalScopeVariable v0 | allocatedVariableReaches ( v0 , source , node ) |
@@ -196,4 +202,6 @@ where
196202 allocatedVariableReaches ( v , def , ret ) and
197203 ret .getAChild * ( ) = v .getAnAccess ( )
198204 )
199- select def , "The memory allocated here may not be released at $@." , ret , "this exit point"
205+ select
206+ def , "The memory allocated here may not be released at $@." ,
207+ ret , "this exit point"
0 commit comments