Amit Thukral - 2021-06-24

int function1 ()
{
char tmpStr;
tmpStr = (char )malloc( 20sizeof(char) );
int ret=sprintf(p, "\nthis is my string\n");
function2(tmpStr);
return ret;
}

As I understood, there is limitation that cppcheck cannot know if function2 would free the memory. Hence, it doesn't say anything whether function1 has memory leak or not.
However, I see that there are couple of ways to get this reported by cppcheck by
1) by using .cfg and using leak-ignore
2) if developer knows, if there exists a function which frees it -- this is done by using "dealloc" and "use"

My question is regarding- if I use "function2" in .cfg like below:
<alloc>function1 </alloc>
<dealloc>function2 </dealloc>
i.e. telling cppcheck that function2 will is handling the deallocation. But, what if there is some bug in function2 or even if it doesn't free the memory at all, there is not error reported by cppcheck.

I want to figure out if there is a way to tell cppcheck that resource will be freed by some function, but if that function doesn't free the memory in some scenarios, it should get reported by cppcheck. Is there any way ?