소스 검색

Release MQTT client on initialization failures

SybexXx 1 일 전
부모
커밋
2c96eb9235
1개의 변경된 파일과 6개의 추가작업 그리고 0개의 파일을 삭제
  1. 6 0
      code/components/jomjol_mqtt/interface_mqtt.cpp

+ 6 - 0
code/components/jomjol_mqtt/interface_mqtt.cpp

@@ -355,6 +355,9 @@ int MQTT_Init() {
         if (ret != ESP_OK)
         {
             LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Could not register event (ret=" + std::to_string(ret) + ")!");
+            esp_mqtt_client_destroy(client);
+            client = NULL;
+            mqtt_connected = false;
             mqtt_initialized = false;
             return -1;
         }
@@ -366,6 +369,9 @@ int MQTT_Init() {
         if (ret != ESP_OK)
         {
             LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Client start failed (retval=" + std::to_string(ret) + ")!");
+            esp_mqtt_client_destroy(client);
+            client = NULL;
+            mqtt_connected = false;
             mqtt_initialized = false;
             return -1;
         }