Skip to content

Commit 3e18a9b

Browse files
committed
CPP: Improve the special case for realloc in MemoryMayNotBeFreed.ql.
1 parent 0589be1 commit 3e18a9b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cpp/ql/src/Critical/MemoryMayNotBeFreed.ql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ predicate verifiedRealloc(FunctionCall reallocCall, Variable v, ControlFlowNode
6262
// a realloc followed by a null check at 'node' (return the non-null
6363
// successor, i.e. where the realloc is confirmed to have succeeded)
6464
newV.getAnAssignedValue() = reallocCall and
65-
node.(AnalysedExpr).getNonNullSuccessor(newV) = verified
65+
node.(AnalysedExpr).getNonNullSuccessor(newV) = verified and
6666
// note: this case uses naive flow logic (getAnAssignedValue).
67+
68+
// special case: if the result of the 'realloc' is assigned to the
69+
// same variable, we don't descriminate properly between the old
70+
// and the new allocation; better to not consider this a free at
71+
// all in that case.
72+
newV != v
6773
) or (
6874
// a realloc(ptr, 0), which always succeeds and frees
6975
// (return the realloc itself)

0 commit comments

Comments
 (0)