Hi, I found a false negative regarding the rule memleak.
In the following C++ program, cppcheck should report a memleak warning because memory allocated by malloc is never released. However, cppcheck reports no such warning.
If malloc(10) succeeds, a is returned from main without being passed to free(a), so the allocation is leaked.
The false negative is caused by the trailing return type form of main, not by the static_cast. With int main(), cppcheck reports the leak even when the allocation is written as auto a = static_cast<char *>(malloc(10));. With auto main() -> int, cppcheck misses the leak.
Actual result
Cppcheck reports no memleak warning for the program.
Thanks for checking. My report was based on cppcheck 2.21.0. Since HEAD reports the memleak warning correctly, this appears to have already been fixed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I found a false negative regarding the rule
memleak.In the following C++ program, cppcheck should report a
memleakwarning because memory allocated bymallocis never released. However, cppcheck reports no such warning.If
malloc(10)succeeds,ais returned frommainwithout being passed tofree(a), so the allocation is leaked.The false negative is caused by the trailing return type form of
main, not by thestatic_cast. Withint main(), cppcheck reports the leak even when the allocation is written asauto a = static_cast<char *>(malloc(10));. Withauto main() -> int, cppcheck misses the leak.Actual result
Cppcheck reports no
memleakwarning for the program.Expected result
Cppcheck should report
memleakfora.Verification
The issue was reproduced with:
Version: 2.21.0
With head:
Thanks for checking. My report was based on cppcheck 2.21.0. Since HEAD reports the
memleakwarning correctly, this appears to have already been fixed.