Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 768be9e

Browse files
authored
Merge pull request #5041 from ihsinme/ihsinme-patch-198
CPP: Improve cpp/memory-leak-on-failed-call-to-realloc
2 parents 02d60a2 + f94a7fc commit 768be9e

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.ql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import cpp
1515
import semmle.code.cpp.controlflow.Guards
16+
import semmle.code.cpp.valuenumbering.HashCons
1617

1718
/**
1819
* A function call that potentially does not return (such as `exit`).
@@ -34,13 +35,11 @@ class ReallocCallLeak extends FunctionCall {
3435
Variable v;
3536

3637
ReallocCallLeak() {
37-
exists(AssignExpr ex, VariableAccess va1, VariableAccess va2 |
38-
this.getTarget().hasName("realloc") and
38+
exists(AssignExpr ex |
39+
this.getTarget().hasGlobalOrStdName("realloc") and
3940
this = ex.getRValue() and
40-
va1 = ex.getLValue() and
41-
va2 = this.getArgument(0) and
42-
va1 = v.getAnAccess() and
43-
va2 = v.getAnAccess()
41+
hashCons(ex.getLValue()) = hashCons(this.getArgument(0)) and
42+
v.getAnAccess() = this.getArgument(0)
4443
)
4544
}
4645

0 commit comments

Comments
 (0)