File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -431,12 +431,18 @@ namespace web { namespace http
431431 // Register for notification on cancellation to abort this request.
432432 if (request_ctx->m_request ._cancellation_token () != pplx::cancellation_token::none ())
433433 {
434- ctx->m_cancellationRegistration = request_ctx->m_request ._cancellation_token ().register_callback ([ctx]()
434+ // weak_ptr prevents lambda from taking shared ownership of the context.
435+ // Otherwise context replacement in the handle_status_line() would leak the objects.
436+ std::weak_ptr<linux_client_request_context> ctx_weak (ctx);
437+ ctx->m_cancellationRegistration = request_ctx->m_request ._cancellation_token ().register_callback ([ctx_weak]()
435438 {
436- // Cancel operations and all asio async handlers.
437- ctx->m_connection ->cancel ();
438- // Shut down transmissions, close the socket and prevent connection from being pooled.
439- ctx->m_connection ->close ();
439+ if (auto ctx_lock = ctx_weak.lock ())
440+ {
441+ // Cancel operations and all asio async handlers.
442+ ctx_lock->m_connection ->cancel ();
443+ // Shut down transmissions, close the socket and prevent connection from being pooled.
444+ ctx_lock->m_connection ->close ();
445+ }
440446 });
441447 }
442448 }
You can’t perform that action at this time.
0 commit comments