public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cgzones at googlemail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/94640] New: false-positive leaking FILE pointer assigned to function passed pointer Date: Fri, 17 Apr 2020 13:35:39 +0000 [thread overview] Message-ID: <bug-94640-4@http.gcc.gnu.org/bugzilla/> (raw) 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] ```
next reply other threads:[~2020-04-17 13:35 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-17 13:35 cgzones at googlemail dot com [this message] 2020-08-13 20:31 ` [Bug analyzer/94640] " dmalcolm at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-94640-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).