public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/94355] support for C++ new expression
Date: Wed, 09 Sep 2020 21:50:42 +0000	[thread overview]
Message-ID: <bug-94355-4-cv6UOxTkFH@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94355-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94355

--- Comment #4 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to Ivan Sorokin from comment #0)
> At the moment static analyzer warns about leaked malloc. It would be great
> if C++ new expression were also supported.
> 
> Example:
> 
> void f()
> {
>     char* p = new char;
> }
> 
> Expected diagnostic:
> 
> warning: leak of 'p' [CWE-401] [-Wanalyzer-malloc-leak]
> 
>     3 |     char* p = new char;

Actual diagnostic with commit
r11-3090-g1690a839cff2e0276017a013419d81d675bbf69d:

demo.cc: In function ‘void f()’:
demo.cc:4:1: warning: leak of ‘p’ [CWE-401] [-Wanalyzer-malloc-leak]
    4 | }
      | ^
  ‘void f()’: events 1-2
    |
    |    3 |     char* p = new char;
    |      |                   ^~~~
    |      |                   |
    |      |                   (1) allocated here
    |    4 | }
    |      | ~                  
    |      | |
    |      | (2) ‘p’ leaks here; was allocated at (1)
    |

where the diagnostic's location is at the point where "p" goes out of scope. 
There's an argument that it would be better emitting it at the "new".

  parent reply	other threads:[~2020-09-09 21:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-27 11:36 [Bug analyzer/94355] New: " vanyacpp at gmail dot com
2020-03-27 11:59 ` [Bug analyzer/94355] " redi at gcc dot gnu.org
2020-09-09 21:24 ` cvs-commit at gcc dot gnu.org
2020-09-09 21:44 ` dmalcolm at gcc dot gnu.org
2020-09-09 21:50 ` dmalcolm at gcc dot gnu.org [this message]
2020-09-26  1:35 ` cvs-commit at gcc dot gnu.org
2021-04-12  7:46 ` vanyacpp at gmail dot com
2021-04-12  8:04 ` vanyacpp at gmail dot com
2021-07-22 21:14 ` navarre.gcc.bugs at gmail dot com
2021-07-22 21:35 ` redi at gcc dot gnu.org
2022-11-05  9:21 ` redi at gcc dot gnu.org
2022-11-05  9:28 ` redi at gcc dot gnu.org
2022-11-05  9:59 ` redi at gcc dot gnu.org
2022-11-05 16:44 ` dmalcolm at gcc dot gnu.org
2022-11-05 21:31 ` redi at gcc dot gnu.org
2023-06-29 20:01 ` [Bug analyzer/94355] analyzer " vultkayn at gcc dot gnu.org
2023-09-01 20:06 ` cvs-commit 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-94355-4-cv6UOxTkFH@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: link
Be 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).