This gives with cppcheck --enable=all test.c --library=gnu.cfg
test.c:9:5: error: Memory leak: test [memleak]
return 0;
^
test.c:6:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable]
test = malloc(5);
^
This gives following errors which are correct:
test.c:9:5: error: Memory leak: test [memleak]
return 0;
^
test.c:8:21: error: Null pointer dereference [nullPointer]
(void) asprintf(NULL, "%s_1", "test");
^
test.c:6:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable]
test = malloc(5);
^
This gives with cppcheck --enable=all test.c --library=gnu.cfg
test.c:9:5: error: Memory leak: test [memleak]
return 0;
^
test.c:6:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable]
test = malloc(5);
^
But once I do:
This gives no errors, while I was expecting 2 leaks here (the malloc and the asprintf allocation)
If I do:
This gives following errors which are correct:
test.c:9:5: error: Memory leak: test [memleak]
return 0;
^
test.c:8:21: error: Null pointer dereference [nullPointer]
(void) asprintf(NULL, "%s_1", "test");
^
test.c:6:10: style: Variable 'test' is assigned a value that is never used. [unreadVariable]
test = malloc(5);
^
Why is
from gnu.cfg not getting hit?
Last edit: Pieter D 2023-11-14
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/12186