public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "zbyszek at in dot waw.pl" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/94399] New: analyzer reports false positives for stuff freed using __attribute__((cleanup())) Date: Mon, 30 Mar 2020 09:24:04 +0000 [thread overview] Message-ID: <bug-94399-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94399 Bug ID: 94399 Summary: analyzer reports false positives for stuff freed using __attribute__((cleanup())) Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: zbyszek at in dot waw.pl Target Milestone: --- Created attachment 48142 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48142&action=edit test program $ rpm -q gcc gcc-10.0.1-0.9.fc32.x86_64 $ cat testfree.c #include <stdlib.h> #define _cleanup_(f) __attribute__((cleanup(f))) static inline void freep(void **p) { free(*p); } void test(void) { _cleanup_(freep) void *ptr; ptr = malloc(3); } int main(void) { test(); return 0; } $ gcc -fanalyzer testfree.c -o testfree testfree.c: In function ‘test’: testfree.c:13:1: warning: leak of ‘ptr’ [CWE-401] [-Wanalyzer-malloc-leak] 13 | } | ^ ‘test’: events 1-4 | | 9 | void test(void) { | | ^~~~ | | | | | (1) entry to ‘test’ | 10 | _cleanup_(freep) void *ptr; | | ~~~ | | | | | (4) calling ‘freep’ from ‘test’ | 11 | | 12 | ptr = malloc(3); | | ~~~~~~~~~~~~~~~ | | | | | | | (2) allocated here | | (3) allocated here | +--> ‘freep’: events 5-6 | | 5 | static inline void freep(void **p) { | | ^~~~~ | | | | | (5) entry to ‘freep’ | 6 | free(*p); | | ~~~~~~~~ | | | | | (6) state of ‘ptr’: ‘start’ -> ‘freed’ (origin: NULL) | <------+ | ‘test’: events 7-8 | | 10 | _cleanup_(freep) void *ptr; | | ^~~ | | | | | (7) returning to ‘test’ from ‘freep’ |...... | 13 | } | | ~ | | | | | (8) ‘ptr’ leaks here; was allocated at (3) | It seems that the analyzer knows that the pointer was freed (event 6), but then still reports a leak (8).
next reply other threads:[~2020-03-30 9:24 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-30 9:24 zbyszek at in dot waw.pl [this message] 2020-08-13 20:28 ` [Bug analyzer/94399] " dmalcolm at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-94399-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).