Hi, I found a false negative in Cppcheck 2.21.0 when a pointer allocated by scalar new is stored in an object member and released with delete[].
new
delete[]
Affected tool
Cppcheck 2.21.0
Affected checker
mismatchAllocDealloc
Minimal reproducer
struct Owner { int *data; }; void test() { Owner owner; owner.data = new int; delete[] owner.data; }
Reproduction command
cppcheck --version cppcheck --enable=warning --inconclusive --check-level=exhaustive --std=c++17 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' mutant-cppcheck-mismatchallocdealloc-fn-object-member.cpp
Current behavior
Cppcheck emits no mismatchAllocDealloc diagnostic. Its checker report confirms that the warning configuration is active.
Expected behavior
Cppcheck should report that owner.data, allocated by scalar new, is incorrectly released by delete[].
owner.data
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15036
Log in to post a comment.
Hi, I found a false negative in Cppcheck 2.21.0 when a pointer allocated by scalar
newis stored in an object member and released withdelete[].Affected tool
Cppcheck 2.21.0Affected checker
mismatchAllocDeallocMinimal reproducer
Reproduction command
Current behavior
Cppcheck emits no
mismatchAllocDeallocdiagnostic. Its checker report confirms that the warning configuration is active.Expected behavior
Cppcheck should report that
owner.data, allocated by scalarnew, is incorrectly released bydelete[].Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15036