public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hodges.r at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/107288] New: Double-free of temporaries created in statement following co_await
Date: Mon, 17 Oct 2022 08:31:00 +0000	[thread overview]
Message-ID: <bug-107288-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 107288
           Summary: Double-free of temporaries created in statement
                    following co_await
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hodges.r at gmail dot com
  Target Milestone: ---

Compiling the attached program results in a call to abort() due to a double
free of the temporary `foo`.

The problem is in this statement:

```
    co_await chan.async_send({},
                             foo { .s = "hello world", .i = 1 },
                             asio::redirect_error(asio::use_awaitable, ec));
```

Modifying the code to remove the temporary works around the issue:

```
    auto f = foo { .s = "hello world", .i = 1 };
    co_await chan.async_send({},
                             std::move(f),
                             asio::redirect_error(asio::use_awaitable, ec));
```

Compiler command line:

```
$ /usr/bin/c++ -DBOOST_SYSTEM_NO_LIB -DBOOST_THREAD_NO_LIB -DBOOST_URL_NO_LIB=1
-DBOOST_URL_STATIC_LINK=1 -DCPP_JWT_USE_VENDORED_NLOHMANN_JSON
-I/home/rhodges/github/Power-Trade/riskmon/apps/scratch2
-I/home/rhodges/github/Power-Trade/riskmon/build/apps/scratch2
-I/home/rhodges/github/Power-Trade/riskmon/libs
-I/home/rhodges/github/Power-Trade/riskmon/build/_deps/boost_url-src/include
-isystem /home/rhodges/work/gcc/include -g -save-temps -std=gnu++20 scratch2
/home/rhodges/github/Power-Trade/riskmon/apps/scratch2/main.cpp
```

Result of running the program:
```
$ ./scratch2 
munmap_chunk(): invalid pointer
Aborted (core dumped)
```

             reply	other threads:[~2022-10-17  8:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17  8:31 hodges.r at gmail dot com [this message]
2022-10-17  8:36 ` [Bug c++/107288] " hodges.r at gmail dot com
2022-10-17 12:01 ` marxin at gcc dot gnu.org
2022-10-18 10:47 ` hodges.r at gmail dot com
2023-04-22 19:40 ` [Bug c++/107288] coroutines: " StevenSun2021 at hotmail dot com
2024-05-06  6:25 ` accelerator0099 at gmail dot com

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