mqtt: Check conn_state before create request for sub_unsub

This also avoid a request leak in client->conn_state == TCP_DISCONNECTED error
path.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
This commit is contained in:
Axel Lin 2016-12-20 23:00:57 +08:00 committed by Dirk Ziegelmeier
parent 876720593b
commit d5bc856f45

View File

@ -1137,15 +1137,14 @@ mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_
LWIP_ERROR("mqtt_publish: total length overflow", (total_len <= 0xFFFF), return ERR_ARG);
remaining_length = (u16_t)total_len;
pkt_id = msg_generate_packet_id(client);
r = mqtt_create_request(client->req_list, pkt_id, cb, arg);
LWIP_ASSERT("mqtt_sub_unsub: qos < 3", qos < 3);
if(client->conn_state == TCP_DISCONNECTED) {
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_sub_unsub: Can not (un)subscribe in disconnected state\n"));
return ERR_CONN;
}
pkt_id = msg_generate_packet_id(client);
r = mqtt_create_request(client->req_list, pkt_id, cb, arg);
if(r == NULL) {
return ERR_MEM;
}