From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DA154382CC18; Sun, 1 Aug 2021 07:20:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA154382CC18 From: "eggert at cs dot ucla.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/101713] New: -Wanalyzer-malloc-leak false positive with GNU coreutils hash table code Date: Sun, 01 Aug 2021 07:20:41 +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: 11.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eggert at cs dot ucla.edu 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: Sun, 01 Aug 2021 07:20:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101713 Bug ID: 101713 Summary: -Wanalyzer-malloc-leak false positive with GNU coreutils hash table code Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: eggert at cs dot ucla.edu Target Milestone: --- Because of GCC bug 94458 we've been disabling -Wanalyzer-malloc-leak when compiling Gnulib-based code such as GNU coreutils. Since GCC bug 94458 is f= ixed I thought I'd try enabling that warning. I simplified the first false posit= ive I ran into (in gnulib/lib/exclude.c) to the following: void free (void *); char *xstrdup (char const *) __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (free, 1))) __attribute__ ((__returns_nonnull__)); void *hash_insert (void const *entry); void addpat (char *pattern) { char *str =3D xstrdup (pattern); hash_insert (str); } For this example, the command 'gcc -fanalyzer -Wanalyzer-too-complex -O2 -S t1.i' outputs the following diagnostic, which is a false alarm because 'str' has been put into a hash table and has not leaked. Omitting the 'const' from the declaration of the 'entry' formal parameter makes the false alarm go aw= ay, but we shouldn't have to omit the 'const'. For now, I think we'll continue = to disable -Wanalyzer-too-complex in Gnulib-derived code. t1.i: In function =E2=80=98addpat=E2=80=99: t1.i:12:1: warning: leak of =E2=80=98str=E2=80=99 [CWE-401] [-Wanalyzer-mal= loc-leak] 12 | } | ^ =E2=80=98addpat=E2=80=99: events 1-2 | | 10 | char *str =3D xstrdup (pattern); | | ^~~~~~~~~~~~~~~~~ | | | | | (1) allocated here | 11 | hash_insert (str); | 12 | } | | ~ | | | | | (2) =E2=80=98str=E2=80=99 leaks here; was allocated at (1) |=