Hi, I am scaning the following code with cppcheck, it seems cppcheck can not detect memory leak in switch case sentences, and its following codes.
If I delete the switch case code, it will detect all leaks.
I've tested on the latest github release and cppcheck2.0.
////////Mytestcode://///////////////voidfunc()
{
char*test=(char*)nwy_malloc(100); //leak can be detected
}
intfunc2()
{
switch(x) {
case1:
break;case2:
{
inta;break;
}
case3:
char*p=malloc(100); **//leak can not be detected**memset(p, 0, 100);break;default:
break;
}
char*p1=malloc(100); **//leak can not be detected if prev switch exist**memset(p1, 0, 100);char*p2=(char*)nwy_malloc(100); **//leak can not be detected if prev switch exist**memset(p2, 0, 100);char*p3=nwy_modem_mem_alloc(100, 20); **//leak can not be detected if prev switch exist**memset(p3, 0, 100);char*p4=nwy_modem_mem_alloc(100);memset(p4, 0, 100);return0;
}
///////////////////////////////////command/////////////////////////////////////////
cppcheck$ ./cppcheck.new -q --enable=all --library=nwy.cfg test.c
test.c:6:1: error: Memory leak: test [memleak]
}
^
test.c:5:13: style: Variable 'test' is assigned a value that is never used. [unreadVariable]
char test = (char )nwy_malloc(100);
^
test.c:16:7: style: Unused variable: a [unusedVariable]
int a;
^
test.c:3:0: style: The function 'func' is never used. [unusedFunction]
Hi, I am scaning the following code with cppcheck, it seems cppcheck can not detect memory leak in switch case sentences, and its following codes.
If I delete the switch case code, it will detect all leaks.
I've tested on the latest github release and cppcheck2.0.
///////////////////////////////////command/////////////////////////////////////////
cppcheck$ ./cppcheck.new -q --enable=all --library=nwy.cfg test.c
test.c:6:1: error: Memory leak: test [memleak]
}
^
test.c:5:13: style: Variable 'test' is assigned a value that is never used. [unreadVariable]
char test = (char )nwy_malloc(100);
^
test.c:16:7: style: Unused variable: a [unusedVariable]
int a;
^
test.c:3:0: style: The function 'func' is never used. [unusedFunction]
^
my config file:<nwy.cfg></nwy.cfg>
Last edit: reddy 2020-10-22