Open
Description
int main(int argc, char** argv)
{
int port;
FILE* fp;
/* Cmd.-line args */
if (argc != 4 ||
(fp = fopen(argv[1], "r")) == 0 ||
((port = atoi(argv[3])) & ~0xFFFF)) {
fputs("\nUSAGE:\n"
"test_fw <inp_file> <host> <port>\n\n", stderr);
return 1; // <== Opened stream never closed. Potential resource leak
}
...
/* some work is done here */
...
}
Return from main()
with an open file does not pose any resource leaks, as the file gets closed by C RTL right away.
It if was any other function, then yes, in such a situation the report would be justified and true, but not for main()
.