From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 56B92385C426; Fri, 17 Apr 2020 13:35:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56B92385C426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587130539; bh=MXdA98KUIYe5rSnbD1aNY8iwLfL2A4KYvhezIsIuBj0=; h=From:To:Subject:Date:From; b=N1RvAxP+G2CnAZmGdopZEIIOuqekyHGxFs0akSs7UAV/FSHgKCVJro/ZR0AZw+idM vjUdZ5MoF+agjpNdOINunPXyd8R4MHPhb0P7eAAkQXWbBGhboGWsKTeD3tw/OToVt2 dy6JiI860JJ53Vh8yiQaUpagWBEbY2sUQaZsq6zM= From: "cgzones at googlemail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cgzones at googlemail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Apr 2020 13:35:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94640 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 int debug; int opencfgfile(const char *cfgfile, FILE **fd) { if (cfgfile[0] !=3D '\0') { if ((*fd =3D fopen(cfgfile, "r")) !=3D NULL) { if (debug) // <-- this seems to trigger the fp printf("Config file: --config\n"); } } return 2; } ``` Original code: https://github.com/vergoh/vnstat/blob/f98c27eaba27ebda703737f8a5539a77b8915= 61e/src/cfg.c#L364 GCC analyzer output: ``` $ gcc-10 -c -Wall -Wextra -fanalyzer return_filepointer.c return_filepointer.c: In function =E2=80=98opencfgfile=E2=80=99: return_filepointer.c:10:8: warning: leak of FILE =E2=80=98=E2=80= =99 [CWE-775] [-Wanalyzer-file-leak] 10 | if (debug) | ^~~~~ =E2=80=98opencfgfile=E2=80=99: events 1-7 | | 7 | if (cfgfile[0] !=3D '\0') { | | ^ | | | | | (1) following =E2=80=98true=E2=80=99 branch... | 8 |=20 | 9 | if ((*fd =3D fopen(cfgfile, "r")) !=3D NULL) { | | ~ ~~~~~~~~~~~~~~~~~~~ | | | | | | | (2) ...to here | | | (3) opened here | | (4) assuming =E2=80=98=E2=80=99 is= non-NULL | | (5) following =E2=80=98true=E2=80=99 branch= ... | 10 | if (debug) | | ~~~~~ | | | | | (6) ...to here | | (7) =E2=80=98=E2=80=99 leaks here; was opened = at (3) | ``` GCC version: ``` gcc-10 (Debian 10-20200411-1) 10.0.1 20200411 (experimental) [master revisi= on bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566] ```=