<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/133942>133942</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            False-positive: fopen() without fclose() in main() reported as a "resource leak"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alavrentiev
      </td>
    </tr>
</table>

<pre>
    ```
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()`.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxslN-Po0YMx_8a82ItGgbIjwcestmlOumkVtf2-TQBE-aOzKAZkzQv_dsrA9l01UZIcRzPZ-yvbUyM9uyIKihfoXxLzMS9D5UZzDWQY0vX5OTbewUbtT7qYB3jxVgHeiemCecG9BGb3gTQB9AHcV1B70EdYPsK6oCIKKGIow8M-cNXf_n6LvHduPhWN-havMdLm74M1pHwIs7s-kHrEPROrkbQGeRvWCDC9ijPErGAdt2I8m_nR3LLiSuUrxmUb5IzaB1Aa8lV7yVQYtX_k0DvJPsZZ9jbJy2faQtCb_Bv9Vdd1_XDsyjQjRPHmaKhPLo_fz_88g75QWxxPW963KeZIn_vbgj50brxe2cHgvxdfvY-8mouer7PmBWljxi5pRAkgQ-p5ROIp-Awg_x1FbkWxlr2ryM5ajFyIHNBR1cK2Aw-Upvib55lGsyAgaKfQkM4kPn56Nf2bbHSNF2MtYPRXwhvPvxEG7H1jrCnQJ86uRxZCP8esm9Lrl3wF4SNWudNStoovFnu0TiUpqIIg62niM4zjj4SGnf_nGgUVUxE7mmJPxPHtTo83fGI3_74isGee0ZzM3fJ6QvLlN1MnHGeewrYTa5h653guCeHd5rR1mGcmh4NRsuTkZD5rkDzyNz8NLR4IvwxRbadpRaNa5HDRHL6NLFo4jzPy-DDfyqWfJK2ytt9vjcJVdm2yEu9UypP-qrbFtRkutWZUWZjtl3edMVG73cNNdRsN4mttNKlKlSWbbVSOi3bsuz2VJSnXdFljYJC0cXYIR2G6yX14ZzYGCeqsjzfFzoZzImG-HhFhEqiXk7TOUKhBhs5Ps-x5YGq2gyRXkYfLdsrQX742D_ZCOmenxi7Wf_VaR0-K151E5kimnlLP42d1skUhqpnHqMs0TzKZ8v9dEobfwFdS0Lr18sY_A9qGHQ9VxVB12th10r_EwAA__-N0HUz">