From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4BE1A385AC27; Wed, 17 Nov 2021 20:28:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BE1A385AC27 From: "eggert at cs dot ucla.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/101713] -Wanalyzer-malloc-leak false positive with GNU coreutils hash table code Date: Wed, 17 Nov 2021 20:28:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: diagnostic 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: Message-ID: In-Reply-To: References: 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: Wed, 17 Nov 2021 20:28:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101713 --- Comment #2 from eggert at cs dot ucla.edu --- (In reply to David Malcolm from comment #1) > Am I right in thinking that there's a cast somewhere inside the hash table > code that at some point casts away the const from the pointer and frees i= t? Yes there's a cast to void *, but no it doesn't free the storage. Instead, = the caller later is supposed to take ownership of the storage if it removes the item from the hashtable, e.g., the caller can later do this: void *entry =3D hash_remove (pattern); free (entry); where ENTRY will be the same pointer as STR in the sample code I gave earli= er. This means there's no leak in addpat per se.=