https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99042

            Bug ID: 99042
           Summary: file-leak is wrong
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: antonio.chirizzi at gmail dot com
  Target Milestone: ---

Created attachment 50155
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50155&action=edit
Reproducer log.c file for the bug

A file leak warning is shown, but it should not. See attached log.c reproducer.
Please note that I tried to strip the file to a minimum (while trying to leave
all the big complex data structures), but it still shows many warnings due to
undeclared functions (it's part of the git code base)
The leak warning is anyway consistent with what is shown on the real log.c file
in the code base.

In function ‘open_next_file’:
log.c:495:16: warning: leak of FILE ‘<unknown>’ [CWE-775]
[-Wanalyzer-file-leak]
  495 |         return 0;
      |                ^
  ‘open_next_file’: events 1-3
    |
    |  491 |         if ((rev->diffopt.file = fopen(filename.buf, "w")) ==
NULL)
    |      |            ^
    |      |            |
    |      |            (1) following ‘false’ branch...
    |......
    |  494 |         strbuf_release(&filename);
    |      |         ~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |         |
    |      |         (2) ...to here
    |  495 |         return 0;
    |      |                ~
    |      |                |
    |      |                (3) ‘<unknown>’ leaks here
    |

Use "gcc -fanalyzer -c log.c"

Reply via email to