From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B66253857012; Sat, 27 Aug 2022 07:17:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B66253857012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661584638; bh=plTz54s+Q6RzS255iGb5IH3trUREIdaS/zPHTFj/tP4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KQ01UHGvNmuEvi7gg8pUeUzHNZmxkxW2rcAAWgqTCBWAJI7Skkxikp9kzd1HDoEmN rh4Vb/fLD+Wnb+3qrdiAjjSvhjR0X4dESkJeTj3GZNGwR3Ypjb9f4D0DSU7inD/aCS F85PADbdVu6DbgfxDav5z6zvBP0Vy554q+g5W2K4= From: "simon at josefsson dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/106427] -Wuse-after-free=3 false alarm about int (not pointer) variable Date: Sat, 27 Aug 2022 07:17:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.1.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: simon at josefsson dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106427 Simon Josefsson changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |simon at josefsson dot org --- Comment #1 from Simon Josefsson --- I ran into this problem too, here is a simple reproducer: $ gcc -Werror -Wuse-after-free=3D3 -g -O2 -o foo foo.c foo.c: In function 'main': foo.c:18:6: error: pointer may be used after 'free' [-Werror=3Duse-after-fr= ee] 18 | if (strstr (in, "FOO")) | ^ foo.c:21:3: note: call to 'free' here 21 | free (in); | ^~~~~~~~~ cc1: all warnings being treated as errors #include #include extern int readln (char **out); int main (void) { char *in =3D NULL; int i =3D 0; if (!readln (&in)) return 0; if (in =3D=3D NULL) return 0; if (strstr (in, "FOO")) i =3D 1; free (in); in =3D NULL; if (!readln (&in)) return 0; if (in =3D=3D NULL) return 0; free (in); return i; }=