Hi, I found a false negative regarding the rule resourceLeak.
resourceLeak
Cppcheck misses the resource leak when the null check uses a local alias of the file pointer.
#include <cstdio> int f() { const FILE *a = fopen("input.txt", "r"); const FILE *b = a; if (!b) return 0; return 0; }
Cppcheck does not report resourceLeak. Removing b and changing the condition to if (!a) produces the warning.
b
if (!a)
Cppcheck should report the missing fclose in both forms.
fclose
The issue was reproduced with:
cppcheck --output-format=xmlv2 --enable=all file_alias.cpp
Version: 2.21.0
See https://trac.cppcheck.net/ticket/2853
Log in to post a comment.
Hi, I found a false negative regarding the rule
resourceLeak.Cppcheck misses the resource leak when the null check uses a local alias of the file pointer.
Actual result
Cppcheck does not report
resourceLeak. Removingband changing the condition toif (!a)produces the warning.Expected result
Cppcheck should report the missing
fclosein both forms.Verification
The issue was reproduced with:
Version: 2.21.0
See https://trac.cppcheck.net/ticket/2853