Skip to content

Commit 41e7d21

Browse files
author
spikelin
committed
fix some potential bugs
1 parent 360f6bb commit 41e7d21

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

sdk_src/protocol/mqtt/mqtt_client.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ int IOT_MQTT_Destroy(void **pClient)
153153
Qcloud_IoT_Client *mqtt_client = (Qcloud_IoT_Client *)(*pClient);
154154

155155
int rc = qcloud_iot_mqtt_disconnect(mqtt_client);
156+
// disconnect network stack by force
157+
if (rc != QCLOUD_RET_SUCCESS) {
158+
mqtt_client->network_stack.disconnect(&(mqtt_client->network_stack));
159+
set_client_conn_state(mqtt_client, NOTCONNECTED);
160+
}
156161

157162
int i = 0;
158163
for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) {

sdk_src/services/shadow/shadow_client.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ void* IOT_Shadow_Construct(ShadowInitParams *pParams)
157157
rc = qcloud_iot_shadow_init(shadow_client);
158158
if (rc != QCLOUD_RET_SUCCESS) {
159159
IOT_Shadow_Destroy(shadow_client);
160-
HAL_Free(shadow_client);
161160
goto End;
162161
}
163162

sdk_src/services/shadow/shadow_client_manager.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int _publish_operation_to_cloud(Qcloud_IoT_Shadow *pShadow, Method method
6464

6565
static int _add_request_to_list(Qcloud_IoT_Shadow *pShadow, const char *pClientToken, RequestParams *pParams);
6666

67-
static int _unsubscribe_operation_result_to_cloud(void *pClient);
67+
static int _unsubscribe_operation_result_to_cloud(Qcloud_IoT_Shadow *pShadow);
6868

6969
static void _traverse_list(Qcloud_IoT_Shadow *pShadow, List *list, const char *pClientToken, const char *pType, TraverseHandle traverseHandle);
7070

@@ -110,7 +110,7 @@ void qcloud_iot_shadow_reset(void *pClient)
110110
list_destroy(shadow_client->inner_data.property_handle_list);
111111
}
112112

113-
_unsubscribe_operation_result_to_cloud(shadow_client->mqtt);
113+
_unsubscribe_operation_result_to_cloud(shadow_client);
114114

115115
if (shadow_client->inner_data.request_list) {
116116
list_destroy(shadow_client->inner_data.request_list);
@@ -403,22 +403,17 @@ static int _set_shadow_json_type(char *pJsonDoc, size_t sizeOfBuffer, Method met
403403
/**
404404
* @brief unsubsribe topic: $shadow/operation/result/{ProductId}/{DeviceName}
405405
*/
406-
static int _unsubscribe_operation_result_to_cloud(void* pClient)
406+
static int _unsubscribe_operation_result_to_cloud(Qcloud_IoT_Shadow *pShadow)
407407
{
408408
IOT_FUNC_ENTRY;
409409
int rc = QCLOUD_RET_SUCCESS;
410410

411-
char operation_result_topic[MAX_SIZE_OF_CLOUD_TOPIC] = {0};
412-
int size = HAL_Snprintf(operation_result_topic, MAX_SIZE_OF_CLOUD_TOPIC, "$shadow/operation/result/%s/%s", iot_device_info_get()->product_id, iot_device_info_get()->device_name);
413-
414-
if (size < 0 || size > MAX_SIZE_OF_CLOUD_TOPIC - 1) {
415-
Log_e("buf size < topic length!");
416-
IOT_FUNC_EXIT_RC(QCLOUD_ERR_FAILURE);
417-
}
418-
419-
IOT_MQTT_Unsubscribe(pClient, operation_result_topic);
411+
if (pShadow->inner_data.result_topic == NULL)
412+
IOT_FUNC_EXIT_RC(rc);
413+
414+
rc = IOT_MQTT_Unsubscribe(pShadow->mqtt, pShadow->inner_data.result_topic);
420415
if (rc < 0) {
421-
Log_e("unsubscribe topic: %s failed: %d.", operation_result_topic, rc);
416+
Log_e("unsubscribe topic: %s failed: %d.", pShadow->inner_data.result_topic, rc);
422417
}
423418

424419
IOT_FUNC_EXIT_RC(rc);

0 commit comments

Comments
 (0)