Skip to content

停止mqtt客户端,会出现释放内存异常导致死机 #123

@wen-vancouver

Description

@wen-vancouver

环境:rtthread标准版,采用kawaii最新版本
调用顺序
先mqtt_disconnect();停止连接
后mqtt_release();释放内存
typedef struct {
// rt_mq_t queue; /< mqtt receive data queue */
uint8_t reconnecttime;//重连次数 用于重启mqtt
mqtt_client_t *client; /
< mqtt client */

 bool is_started;

char clientid[128];//clientid=设备id(4bytes)+MAC(6bytes) 组成的字符串

char topo_topic[200];//公共主题缓存
char *data;
int data_len;
char *topic;
int topic_len;

} mesh_mqtt_handle_t;

esp_err_t mesh_mqtt_stop(void)
{
if(g_mesh_mqtt.client==NULL)
{
LOG_I("mqtt client is not connected.");
return ESP_FAIL;
}

mqtt_disconnect(g_mesh_mqtt.client);
mqtt_release(g_mesh_mqtt.client);

LOG_I("mesh_mqtt_stop");

// //心跳任务停止
if(heartbeatHandle)
{
	rt_thread_delete(heartbeatHandle);
	heartbeatHandle=NULL;
}

g_mesh_mqtt.client = NULL;

memset(&g_mesh_mqtt,0,sizeof(g_mesh_mqtt));//全部置0

return ESP_OK;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions