public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/94640] New: false-positive leaking FILE pointer assigned to function passed pointer
@ 2020-04-17 13:35 cgzones at googlemail dot com
  2020-08-13 20:31 ` [Bug analyzer/94640] " dmalcolm at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: cgzones at googlemail dot com @ 2020-04-17 13:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94640
           Summary: false-positive leaking FILE pointer assigned to
                    function passed pointer
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: cgzones at googlemail dot com
  Target Milestone: ---

Minimized code snippet:
```
#include <stdio.h>

int debug;

int opencfgfile(const char *cfgfile, FILE **fd)
{
        if (cfgfile[0] != '\0') {

                if ((*fd = fopen(cfgfile, "r")) != NULL) {
                        if (debug)   // <-- this seems to trigger the fp
                                printf("Config file: --config\n");
                }

        }

        return 2;
}
```

Original code:
https://github.com/vergoh/vnstat/blob/f98c27eaba27ebda703737f8a5539a77b891561e/src/cfg.c#L364

GCC analyzer output:
```
$ gcc-10 -c -Wall -Wextra -fanalyzer return_filepointer.c
return_filepointer.c: In function ‘opencfgfile’:
return_filepointer.c:10:8: warning: leak of FILE ‘<unknown>’ [CWE-775]
[-Wanalyzer-file-leak]
   10 |    if (debug)
      |        ^~~~~
  ‘opencfgfile’: events 1-7
    |
    |    7 |         if (cfgfile[0] != '\0') {
    |      |            ^
    |      |            |
    |      |            (1) following ‘true’ branch...
    |    8 | 
    |    9 |                 if ((*fd = fopen(cfgfile, "r")) != NULL) {
    |      |                    ~       ~~~~~~~~~~~~~~~~~~~
    |      |                    |       |
    |      |                    |       (2) ...to here
    |      |                    |       (3) opened here
    |      |                    (4) assuming ‘<unknown>’ is non-NULL
    |      |                    (5) following ‘true’ branch...
    |   10 |    if (debug)
    |      |        ~~~~~
    |      |        |
    |      |        (6) ...to here
    |      |        (7) ‘<unknown>’ leaks here; was opened at (3)
    |
```

GCC version:
```
gcc-10 (Debian 10-20200411-1) 10.0.1 20200411 (experimental) [master revision
bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566]
```

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug analyzer/94640] false-positive leaking FILE pointer assigned to function passed pointer
  2020-04-17 13:35 [Bug analyzer/94640] New: false-positive leaking FILE pointer assigned to function passed pointer cgzones at googlemail dot com
@ 2020-08-13 20:31 ` dmalcolm at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2020-08-13 20:31 UTC (permalink / raw)
  To: gcc-bugs

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

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
The leak false positive should be fixed by
g:808f4dfeb3a95f50f15e71148e5c1067f90a126d (for GCC 11).  Marking this as
fixed.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-13 20:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17 13:35 [Bug analyzer/94640] New: false-positive leaking FILE pointer assigned to function passed pointer cgzones at googlemail dot com
2020-08-13 20:31 ` [Bug analyzer/94640] " dmalcolm at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).