Hi, I found a false negative regarding the rule resourceLeak.
resourceLeak
Cppcheck reports resourceLeak for the original program, but it misses a semantically similar case when the control flow reaches the return statement through a goto label.
goto
#include <stdio.h> int main() { const FILE *a = fopen("good.c", "r"); if (!a) return 0; return 0; }
Cppcheck reports:
<error id="resourceLeak" severity="error" msg="Resource leak: a" ...>
#include <stdio.h> int main() { const FILE *a; a = fopen("good.c", "r"); goto check; check: if (!a) return 0; return 0; }
In this program, if fopen succeeds, a is returned without being closed by fclose(a), so the file resource is leaked.
fopen
a
fclose(a)
Cppcheck reports no resourceLeak warning for the reproducing program.
Cppcheck should report resourceLeak for a.
The issue was reproduced with:
cppcheck --output-format=xmlv2 --enable=all resource_leak_goto.cpp
Version: 2.21.0
Log in to post a comment.
Hi, I found a false negative regarding the rule
resourceLeak.Cppcheck reports
resourceLeakfor the original program, but it misses a semantically similar case when the control flow reaches the return statement through agotolabel.Original seed program
Cppcheck reports:
Reproducing program
In this program, if
fopensucceeds,ais returned without being closed byfclose(a), so the file resource is leaked.Actual result
Cppcheck reports no
resourceLeakwarning for the reproducing program.Expected result
Cppcheck should report
resourceLeakfora.Verification
The issue was reproduced with:
Version: 2.21.0