From 30e38527a42320d4ba1c14e7756f0e0f9a816102 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Thu, 28 Feb 2019 10:33:48 +1100 Subject: [PATCH] Capture port by value to prevent dangling reference. --- asio/src/examples/cpp17/coroutines_ts/chat_server.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/asio/src/examples/cpp17/coroutines_ts/chat_server.cpp b/asio/src/examples/cpp17/coroutines_ts/chat_server.cpp index b6c918b2..43622502 100644 --- a/asio/src/examples/cpp17/coroutines_ts/chat_server.cpp +++ b/asio/src/examples/cpp17/coroutines_ts/chat_server.cpp @@ -204,7 +204,10 @@ int main(int argc, char* argv[]) { unsigned short port = std::atoi(argv[i]); co_spawn(io_context, - [&]{ return listener(tcp::acceptor(io_context, {tcp::v4(), port})); }, + [&io_context, port] + { + return listener(tcp::acceptor(io_context, {tcp::v4(), port})); + }, detached); }