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 via email to