public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107288] New: Double-free of temporaries created in statement following co_await
@ 2022-10-17  8:31 hodges.r at gmail dot com
  2022-10-17  8:36 ` [Bug c++/107288] " hodges.r at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hodges.r at gmail dot com @ 2022-10-17  8:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

end of thread, other threads:[~2024-05-06  6:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-17  8:31 [Bug c++/107288] New: Double-free of temporaries created in statement following co_await hodges.r at gmail dot com
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

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