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>
diff --git a/src/apps/mqtt/mqtt.c b/src/apps/mqtt/mqtt.c
index c49000e..fa2ba8b 100644
--- a/src/apps/mqtt/mqtt.c
+++ b/src/apps/mqtt/mqtt.c
@@ -1137,15 +1137,14 @@
   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;
   }