From f58eefbdb64e39bee4b8d09cc93ded9e0374b67e Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Tue, 3 Dec 2019 13:05:44 -0800 Subject: [PATCH] Fixed anyCbData pointer not being properly initialized in all paths. (#82) --- source/mqtt/MqttClient.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/mqtt/MqttClient.cpp b/source/mqtt/MqttClient.cpp index a115f9fb4a3..6d0aca0f200 100644 --- a/source/mqtt/MqttClient.cpp +++ b/source/mqtt/MqttClient.cpp @@ -73,6 +73,8 @@ namespace Aws struct PubCallbackData { + PubCallbackData() : connection(nullptr), allocator(nullptr) {} + MqttConnection *connection; OnPublishReceivedHandler onPublishReceived; Allocator *allocator; @@ -102,6 +104,8 @@ namespace Aws struct OpCompleteCallbackData { + OpCompleteCallbackData() : connection(nullptr), topic(nullptr), allocator(nullptr) {} + MqttConnection *connection; OnOperationCompleteHandler onOperationComplete; const char *topic; @@ -132,6 +136,8 @@ namespace Aws struct SubAckCallbackData { + SubAckCallbackData() : connection(nullptr), topic(nullptr), allocator(nullptr) {} + MqttConnection *connection; OnSubAckHandler onSubAck; const char *topic; @@ -165,6 +171,8 @@ namespace Aws struct MultiSubAckCallbackData { + MultiSubAckCallbackData() : connection(nullptr), topic(nullptr), allocator(nullptr) {} + MqttConnection *connection; OnMultiSubAckHandler onSubAck; const char *topic; @@ -236,11 +244,11 @@ namespace Aws aws_mqtt_transform_websocket_handshake_complete_fn *complete_fn, void *complete_ctx) { - MqttConnection *connection = reinterpret_cast(user_data); + auto connection = reinterpret_cast(user_data); Allocator *allocator = connection->m_owningClient->allocator; // we have to do this because of private constructors. - Http::HttpRequest *toSeat = + auto toSeat = reinterpret_cast(aws_mem_acquire(allocator, sizeof(Http::HttpRequest))); toSeat = new (toSeat) Http::HttpRequest(allocator, rawRequest); @@ -265,7 +273,7 @@ namespace Aws const Crt::Io::TlsContext &tlsContext, bool useWebsocket) noexcept : m_owningClient(client), m_tlsContext(tlsContext), m_tlsOptions(tlsContext.NewConnectionOptions()), - m_useTls(true), m_useWebsocket(useWebsocket) + m_onAnyCbData(nullptr), m_useTls(true), m_useWebsocket(useWebsocket) { s_connectionInit(this, hostName, port, socketOptions); }