Skip to content

Commit 4aea4c0

Browse files
committed
C++: Simple fix.
1 parent c04428d commit 4aea4c0

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

cpp/ql/src/Critical/MemoryMayNotBeFreed.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ predicate allocCallOrIndirect(Expr e) {
3939
allocCallOrIndirect(rtn.getExpr())
4040
or
4141
// return variable assigned with alloc
42-
exists(Variable v |
42+
exists(StackVariable v |
4343
v = rtn.getExpr().(VariableAccess).getTarget() and
4444
allocCallOrIndirect(v.getAnAssignedValue()) and
4545
not assignedToFieldOrGlobal(v, _)
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
| test_free.cpp:36:22:36:35 | ... = ... | This memory allocation may not be released at $@. | test_free.cpp:38:1:38:1 | return ... | this exit point |
22
| test_free.cpp:267:12:267:17 | call to malloc | This memory allocation may not be released at $@. | test_free.cpp:270:1:270:1 | return ... | this exit point |
3-
| test_free.cpp:420:23:420:31 | call to getBuffer | This memory allocation may not be released at $@. | test_free.cpp:428:1:428:1 | return ... | this exit point |
4-
| test_free.cpp:427:25:427:33 | call to getBuffer | This memory allocation may not be released at $@. | test_free.cpp:428:1:428:1 | return ... | this exit point |

cpp/ql/test/query-tests/Critical/MemoryFreed/test_free.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,12 @@ class HasGetterNoFree {
417417

418418
void testHasGetter() {
419419
HasGetterAndFree hg;
420-
void *buffer = hg.getBuffer(); // GOOD (freed in destructor) [FALSE POSITIVE]
420+
void *buffer = hg.getBuffer(); // GOOD (freed in destructor)
421421

422422
HasGetterNoFree hg2;
423423
void *buffer2 = hg2.getBuffer(); // GOOD (freed below)
424424
free(buffer2);
425425

426426
HasGetterNoFree hg3;
427-
void *buffer3 = hg3.getBuffer(); // BAD (not freed)
427+
void *buffer3 = hg3.getBuffer(); // BAD (not freed) [NOT DETECTED]
428428
}

0 commit comments

Comments
 (0)