Hi, I found a false negative regarding the rule memleak.
memleak
Cppcheck misses the leak when the allocated buffer is accessed through a pointer-to-pointer alias.
#include <stdlib.h> int f(void) { int result = 0; char *a = malloc(10); char **b = &a; if (*b) { (*b)[0] = 0; result = (*b)[0]; } return result; }
Cppcheck does not report memleak. Removing b and replacing each *b access with a produces the warning.
b
*b
a
Cppcheck should report the missing free in both forms.
free
The issue was reproduced with:
cppcheck --output-format=xmlv2 --enable=all malloc_alias.c
Version: 2.21.0
Looks like a special case of https://trac.cppcheck.net/ticket/1606
Log in to post a comment.
Hi, I found a false negative regarding the rule
memleak.Cppcheck misses the leak when the allocated buffer is accessed through a pointer-to-pointer alias.
Actual result
Cppcheck does not report
memleak. Removingband replacing each*baccess withaproduces the warning.Expected result
Cppcheck should report the missing
freein both forms.Verification
The issue was reproduced with:
Version: 2.21.0
Looks like a special case of https://trac.cppcheck.net/ticket/1606