@@ -1585,7 +1585,8 @@ static void esp_mqtt_task(void *pv)
15851585 while (client -> run ) {
15861586 MQTT_API_LOCK (client );
15871587 run_event_loop (client );
1588- switch (client -> state ) {
1588+ mqtt_client_state_t state = client -> state ;
1589+ switch (state ) {
15891590 case MQTT_STATE_DISCONNECTED :
15901591 break ;
15911592 case MQTT_STATE_INIT :
@@ -1874,12 +1875,13 @@ int esp_mqtt_client_subscribe_multiple(esp_mqtt_client_handle_t client,
18741875 if (client -> config -> outbox_limit > 0 && outbox_get_size (client -> outbox ) > client -> config -> outbox_limit ) {
18751876 return -2 ;
18761877 }
1877- MQTT_API_LOCK ( client );
1878+
18781879 if (client -> state != MQTT_STATE_CONNECTED ) {
18791880 ESP_LOGE (TAG , "Client has not connected" );
1880- MQTT_API_UNLOCK (client );
18811881 return -1 ;
18821882 }
1883+
1884+ MQTT_API_LOCK (client );
18831885 if (client -> mqtt_state .connection .information .protocol_ver == MQTT_PROTOCOL_V_5 ) {
18841886#ifdef MQTT_PROTOCOL_5
18851887 int max_qos = topic_list [0 ].qos ;
@@ -1942,12 +1944,11 @@ int esp_mqtt_client_unsubscribe(esp_mqtt_client_handle_t client, const char *top
19421944 ESP_LOGE (TAG , "Client was not initialized" );
19431945 return -1 ;
19441946 }
1945- MQTT_API_LOCK (client );
19461947 if (client -> state != MQTT_STATE_CONNECTED ) {
1947- MQTT_API_UNLOCK (client );
19481948 ESP_LOGE (TAG , "Client has not connected" );
19491949 return -1 ;
19501950 }
1951+ MQTT_API_LOCK (client );
19511952 if (client -> mqtt_state .connection .information .protocol_ver == MQTT_PROTOCOL_V_5 ) {
19521953#ifdef MQTT_PROTOCOL_5
19531954 mqtt5_msg_unsubscribe (& client -> mqtt_state .connection ,
@@ -2049,15 +2050,14 @@ int esp_mqtt_client_publish(esp_mqtt_client_handle_t client, const char *topic,
20492050 ESP_LOGE (TAG , "Client was not initialized" );
20502051 return -1 ;
20512052 }
2052- MQTT_API_LOCK (client );
20532053#if MQTT_SKIP_PUBLISH_IF_DISCONNECTED
20542054 if (client -> state != MQTT_STATE_CONNECTED ) {
20552055 ESP_LOGI (TAG , "Publishing skipped: client is not connected" );
2056- MQTT_API_UNLOCK (client );
20572056 return -1 ;
20582057 }
20592058#endif
20602059
2060+ MQTT_API_LOCK (client );
20612061#ifdef MQTT_PROTOCOL_5
20622062 if (client -> mqtt_state .connection .information .protocol_ver == MQTT_PROTOCOL_V_5 ) {
20632063 if (esp_mqtt5_client_publish_check (client , qos , retain ) != ESP_OK ) {
0 commit comments