Browse Source

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>
STABLE-2_1_x
Axel Lin 9 years ago committed by Dirk Ziegelmeier
parent
commit
d5bc856f45
  1. 5
      src/apps/mqtt/mqtt.c

5
src/apps/mqtt/mqtt.c

@ -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;
}

Loading…
Cancel
Save