public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/108879] New: -Wanalyzer-malloc-leak false positive stl string in try catch block
@ 2023-02-21 22:42 jg at jguk dot org
  2023-02-22 18:16 ` [Bug analyzer/108879] " dmalcolm at gcc dot gnu.org
  2023-02-26 22:52 ` jg at jguk dot org
  0 siblings, 2 replies; 3+ messages in thread
From: jg at jguk dot org @ 2023-02-21 22:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108879
           Summary: -Wanalyzer-malloc-leak false positive stl string in
                    try catch block
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: jg at jguk dot org
  Target Milestone: ---

Tested just now on gcc (trunk). Source code below and the output.

https://godbolt.org/z/Ms6fezGvT

<source>: In function 'void make_string(const char*, std::string&)':
<source>:11:27: warning: leak of
'<anonymous>.std::__cxx11::basic_string<char>::_M_dataplus.std::__cxx11::basic_string<char>::_Alloc_hider::_M_p'
[CWE-401] [-Wanalyzer-malloc-leak]
   11 |         out_string = std::string(str);
      |                           ^~~~~~~~~~~
  'void make_string(const char*, std::string&)': events 1-2
    |
    |    7 | void make_string(const char * const str, std::string & out_string)
    |      |      ^~~~~~~~~~~
    |      |      |
    |      |      (1) entry to 'make_string'
    |......
    |   11 |         out_string = std::string(str);
    |      |                           ~~~~~~~~~~~
    |      |                           |
    |      |                           (2) calling
'std::__cxx11::basic_string<char>::basic_string<>' from 'make_string'





// -fanalyzer -std=c++23 -O1 -Wall -Wno-analyzer-use-of-uninitialized-value

#include <string>
#include <cstdio>

void make_string(const char * const str, std::string & out_string)
{
    try
    {
        out_string = std::string(str);
    }
    catch (std::exception& ex)
    {
        printf("exception %s\n", ex.what());
        fflush(stdout);
    }
}

int main()
{
    std::string str;
    make_string(NULL, str);
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-26 22:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-21 22:42 [Bug analyzer/108879] New: -Wanalyzer-malloc-leak false positive stl string in try catch block jg at jguk dot org
2023-02-22 18:16 ` [Bug analyzer/108879] " dmalcolm at gcc dot gnu.org
2023-02-26 22:52 ` jg at jguk dot org

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).