Skip to content

Commit f58eefb

Browse files
Fixed anyCbData pointer not being properly initialized in all paths. (aws#82)
1 parent 97ccf07 commit f58eefb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

source/mqtt/MqttClient.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ namespace Aws
7373

7474
struct PubCallbackData
7575
{
76+
PubCallbackData() : connection(nullptr), allocator(nullptr) {}
77+
7678
MqttConnection *connection;
7779
OnPublishReceivedHandler onPublishReceived;
7880
Allocator *allocator;
@@ -102,6 +104,8 @@ namespace Aws
102104

103105
struct OpCompleteCallbackData
104106
{
107+
OpCompleteCallbackData() : connection(nullptr), topic(nullptr), allocator(nullptr) {}
108+
105109
MqttConnection *connection;
106110
OnOperationCompleteHandler onOperationComplete;
107111
const char *topic;
@@ -132,6 +136,8 @@ namespace Aws
132136

133137
struct SubAckCallbackData
134138
{
139+
SubAckCallbackData() : connection(nullptr), topic(nullptr), allocator(nullptr) {}
140+
135141
MqttConnection *connection;
136142
OnSubAckHandler onSubAck;
137143
const char *topic;
@@ -165,6 +171,8 @@ namespace Aws
165171

166172
struct MultiSubAckCallbackData
167173
{
174+
MultiSubAckCallbackData() : connection(nullptr), topic(nullptr), allocator(nullptr) {}
175+
168176
MqttConnection *connection;
169177
OnMultiSubAckHandler onSubAck;
170178
const char *topic;
@@ -236,11 +244,11 @@ namespace Aws
236244
aws_mqtt_transform_websocket_handshake_complete_fn *complete_fn,
237245
void *complete_ctx)
238246
{
239-
MqttConnection *connection = reinterpret_cast<MqttConnection *>(user_data);
247+
auto connection = reinterpret_cast<MqttConnection *>(user_data);
240248

241249
Allocator *allocator = connection->m_owningClient->allocator;
242250
// we have to do this because of private constructors.
243-
Http::HttpRequest *toSeat =
251+
auto toSeat =
244252
reinterpret_cast<Http::HttpRequest *>(aws_mem_acquire(allocator, sizeof(Http::HttpRequest)));
245253
toSeat = new (toSeat) Http::HttpRequest(allocator, rawRequest);
246254

@@ -265,7 +273,7 @@ namespace Aws
265273
const Crt::Io::TlsContext &tlsContext,
266274
bool useWebsocket) noexcept
267275
: m_owningClient(client), m_tlsContext(tlsContext), m_tlsOptions(tlsContext.NewConnectionOptions()),
268-
m_useTls(true), m_useWebsocket(useWebsocket)
276+
m_onAnyCbData(nullptr), m_useTls(true), m_useWebsocket(useWebsocket)
269277
{
270278
s_connectionInit(this, hostName, port, socketOptions);
271279
}

0 commit comments

Comments
 (0)