I tried cppcheck with following source, however cppcheck did not report memory leak depending on condition.
#include <stdlib.h> static int foo = 1; static int bar = 1; static void func() { } void main() { char *p = malloc(10); if (p) { if (foo) { if (bar) { #ifdef COND func(); #endif } return; } free(p); } }
ken@ubuntu:~$ cppcheck --version Cppcheck 1.72 ken@ubuntu:~$ cppcheck -DCOND test.c Checking test.c... ken@ubuntu:~$ cppcheck -UCOND test.c Checking test.c... [test.c:21]: (error) Memory leak: p
It looks like false negative...
Latest cppcheck warns:
daniel@debian:~/cppcheck$ ./cppcheck 1.c Checking 1.c ... [1.c:20]: (error) Memory leak: p Checking 1.c: COND...
Strangely ... latest cppcheck does not warn if -DCOND is used.
Log in to post a comment.
I tried cppcheck with following source, however cppcheck did not report memory leak depending on condition.
It looks like false negative...
Latest cppcheck warns:
Strangely ... latest cppcheck does not warn if -DCOND is used.
Last edit: Daniel Marjamäki 2017-03-04