From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 106153858298; Fri, 30 Sep 2022 15:19:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 106153858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664551175; bh=AkeDHl5BzsbP4I5TOggJLjInvjh4G5c4zJMoWVn5FJE=; h=From:To:Subject:Date:From; b=q8K/6Dph4DXSJtt/BVVeI9CgLexcAoll2+IvE4JuTyvET6Ll+pelX7lna1UxIjh7M QhFrYjFXz1hZywvms0NoQ36Rg49AAL8Le1HsWkFQSGxqOO50g/A8+BR8jv87aUa+PX Ijd50EcWCVHHRjiOinKRB2l9Nu+oLY0UiJTu0kFk= From: "eblake at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107100] New: -fanalyzer false positive about leak in function with attribute((malloc)) obtained from another function with attribute((malloc(free,1))) Date: Fri, 30 Sep 2022 15:19:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eblake at redhat dot com 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107100 Bug ID: 107100 Summary: -fanalyzer false positive about leak in function with attribute((malloc)) obtained from another function with attribute((malloc(free,1))) Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: eblake at redhat dot com Target Milestone: --- I'm at a loss for why disabling -O2 or removing __attribute__((malloc(free,= 1))) from function f silences a false-positive warning about a memory leak in function g with __attribute((malloc)) specifically documenting that g() wan= ts to return a just-allocated pointer: $ cat foo.c #include #include char * __attribute__((malloc)) #ifndef HACK __attribute__((malloc(free,1))) #endif f (const char *i) { return strdup (i); } char * __attribute__((malloc)) __attribute__((malloc(free,1))) bar (void) { char *x =3D f ("test"); return x; } $ gcc -O2 -Wsuggest-attribute=3Dmalloc -fanalyzer -o foo.o -c foo.c $ gcc -DHACK -Wsuggest-attribute=3Dmalloc -fanalyzer -o foo.o -c foo.c $ gcc -Wsuggest-attribute=3Dmalloc -fanalyzer -o foo.o -c foo.c foo.c: In function =E2=80=98f=E2=80=99: foo.c:11:10: warning: leak of =E2=80=98x=E2=80=99 [CWE-401] [-Wanalyzer-mal= loc-leak] 11 | return strdup (i); | ^~~~~~~~~~ =E2=80=98bar=E2=80=99: events 1-3 | | 17 | bar (void) | | ^~~ | | | | | (1) entry to =E2=80=98bar=E2=80=99 | 18 | { | 19 | char *x =3D f ("test"); | | ~~~~~~~~~~ | | | | | (2) allocated here | | (3) calling =E2=80=98f=E2=80=99 from =E2=80=98bar= =E2=80=99 | +--> =E2=80=98f=E2=80=99: events 4-5 | | 9 | f (const char *i) | | ^ | | | | | (4) entry to =E2=80=98f=E2=80=99 | 10 | { | 11 | return strdup (i); | | ~~~~~~~~~~ | | | | | (5) =E2=80=98x=E2=80=99 leaks here; was alloca= ted at (2) |=