diff --git a/src/SignalR/clients/cpp/src/signalrclient/connection_impl.cpp b/src/SignalR/clients/cpp/src/signalrclient/connection_impl.cpp index 0195d7d172..26d40e6797 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/connection_impl.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/connection_impl.cpp @@ -95,7 +95,7 @@ namespace signalr pplx::task_completion_event start_tce; - auto weak_connection = weak_from_this(); + std::weak_ptr weak_connection = shared_from_this(); pplx::task_from_result() .then([weak_connection, url]() diff --git a/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.h b/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.h index a1c2c346f6..7a7386db9d 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.h +++ b/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.h @@ -12,7 +12,7 @@ namespace signalr class default_websocket_client : public websocket_client { public: - explicit default_websocket_client(const signalr_client_config& signalr_client_config = signalr_client_config{}) noexcept; + explicit default_websocket_client(const signalr_client_config& signalr_client_config = {}) noexcept; pplx::task connect(const std::string& url) override; diff --git a/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.cpp b/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.cpp index 260794a3eb..8f9d7a0290 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.cpp @@ -50,10 +50,8 @@ namespace signalr void hub_connection_impl::initialize() { - auto this_hub_connection = shared_from_this(); - // weak_ptr prevents a circular dependency leading to memory leak and other problems - auto weak_hub_connection = std::weak_ptr(this_hub_connection); + std::weak_ptr weak_hub_connection = shared_from_this(); m_connection->set_message_received([weak_hub_connection](const std::string& message) { @@ -109,7 +107,7 @@ namespace signalr m_connection->set_client_config(m_signalr_client_config); m_handshakeTask = pplx::task_completion_event(); m_handshakeReceived = false; - auto weak_connection = weak_from_this(); + std::weak_ptr weak_connection = shared_from_this(); return m_connection->start() .then([weak_connection](pplx::task startTask) { @@ -310,7 +308,7 @@ namespace signalr const std::string& callback_id, std::function set_completion, std::function set_exception) { json::value request; - request[_XPLATSTR("type")] = json::value::value(1); + request[_XPLATSTR("type")] = json::value(1); if (!callback_id.empty()) { request[_XPLATSTR("invocationId")] = json::value::string(utility::conversions::to_string_t(callback_id)); @@ -318,10 +316,8 @@ namespace signalr request[_XPLATSTR("target")] = json::value::string(utility::conversions::to_string_t(method_name)); request[_XPLATSTR("arguments")] = arguments; - auto this_hub_connection = shared_from_this(); - // weak_ptr prevents a circular dependency leading to memory leak and other problems - auto weak_hub_connection = std::weak_ptr(this_hub_connection); + auto weak_hub_connection = std::weak_ptr(shared_from_this()); m_connection->send(utility::conversions::to_utf8string(request.serialize() + _XPLATSTR('\x1e'))) .then([set_completion, set_exception, weak_hub_connection, callback_id](pplx::task send_task)