Skip to content

Commit 25e8374

Browse files
committed
Check for valid mqtt_network allocation
Signed-off-by: Ajay Bhargav <[email protected]>
1 parent 82ba4dc commit 25e8374

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

mqttclient/mqttclient.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ static int mqtt_connect_with_results(mqtt_client_t* c)
971971
mqtt_connack_data_t connack_data = {0};
972972
MQTTPacket_connectData connect_data = MQTTPacket_connectData_initializer;
973973

974-
if (NULL == c)
974+
if (NULL == c || NULL == c->mqtt_network)
975975
RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
976976

977977
if (CLIENT_STATE_CONNECTED == mqtt_get_client_state(c))
@@ -983,12 +983,14 @@ static int mqtt_connect_with_results(mqtt_client_t* c)
983983
rc = network_init(c->mqtt_network, c->mqtt_host, c->mqtt_port, NULL);
984984
#endif
985985

986+
if (rc != MQTT_SUCCESS_ERROR) {
987+
RETURN_ERROR(rc);
988+
}
989+
986990
rc = network_connect(c->mqtt_network);
987991
if (MQTT_SUCCESS_ERROR != rc) {
988-
if (NULL != c->mqtt_network) {
989-
network_release(c->mqtt_network);
990-
RETURN_ERROR(rc);
991-
}
992+
network_release(c->mqtt_network);
993+
RETURN_ERROR(rc);
992994
}
993995

994996
MQTT_LOG_I("mqtt-client:%d %s()... mqtt connect success...", __LINE__, __FUNCTION__);

0 commit comments

Comments
 (0)