Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitefb9d8c

Browse files
committed
Fix potential use-after-free of Connection from Asio thread
1 parent6ba7d7f commitefb9d8c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

‎include/crow/websocket.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
257257
/// Sets a flag to destroy the object once the message is sent.
258258
voidclose(std::stringconst& msg,uint16_t status_code)override
259259
{
260-
dispatch([this, msg, status_code]()mutable {
260+
dispatch([this,shared_this =this->shared_from_this(),msg, status_code]()mutable {
261261
has_sent_close_ =true;
262262
if (has_recv_close_ && !is_close_handler_called_)
263263
{
@@ -371,7 +371,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
371371
//asio::async_read(adaptor_.socket(), asio::buffer(&mini_header_, 1),
372372
adaptor_.socket().async_read_some(
373373
asio::buffer(&mini_header_,2),
374-
[this](const error_code& ec, std::size_t
374+
[this, shared_this =this->shared_from_this()](const error_code& ec, std::size_t
375375
#ifdef CROW_ENABLE_DEBUG
376376
bytes_transferred
377377
#endif
@@ -439,7 +439,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
439439
remaining_length16_ =0;
440440
asio::async_read(
441441
adaptor_.socket(),asio::buffer(&remaining_length16_,2),
442-
[this](const error_code& ec, std::size_t
442+
[this, shared_this =this->shared_from_this()](const error_code& ec, std::size_t
443443
#ifdef CROW_ENABLE_DEBUG
444444
bytes_transferred
445445
#endif
@@ -475,7 +475,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
475475
{
476476
asio::async_read(
477477
adaptor_.socket(),asio::buffer(&remaining_length_,8),
478-
[this](const error_code& ec, std::size_t
478+
[this, shared_this =this->shared_from_this()](const error_code& ec, std::size_t
479479
#ifdef CROW_ENABLE_DEBUG
480480
bytes_transferred
481481
#endif
@@ -519,7 +519,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
519519
{
520520
asio::async_read(
521521
adaptor_.socket(),asio::buffer((char*)&mask_,4),
522-
[this](const error_code& ec, std::size_t
522+
[this, shared_this =this->shared_from_this()](const error_code& ec, std::size_t
523523
#ifdef CROW_ENABLE_DEBUG
524524
bytes_transferred
525525
#endif
@@ -561,7 +561,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
561561
to_read = remaining_length_;
562562
adaptor_.socket().async_read_some(
563563
asio::buffer(buffer_,static_cast<std::size_t>(to_read)),
564-
[this](const error_code& ec, std::size_t bytes_transferred) {
564+
[this, shared_this =this->shared_from_this()](const error_code& ec, std::size_t bytes_transferred) {
565565
is_reading =false;
566566

567567
if (!ec)
@@ -728,7 +728,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
728728
auto watch = std::weak_ptr<void>{anchor_};
729729
asio::async_write(
730730
adaptor_.socket(), buffers,
731-
[this, watch](const error_code& ec, std::size_t/*bytes_transferred*/) {
731+
[this,shared_this =this->shared_from_this(),watch](const error_code& ec, std::size_t/*bytes_transferred*/) {
732732
auto anchor = watch.lock();
733733
if (anchor ==nullptr)
734734
return;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp