fix mem break when mqtt_thread not exit

This commit is contained in:
lyon 2022-11-20 00:17:34 +08:00
parent d1499ff983
commit 1c55ca0223
4 changed files with 20 additions and 4 deletions

View File

@ -1612,7 +1612,12 @@ int mqtt_set_will_options(mqtt_client_t* c,
}
int mqtt_release_free(mqtt_client_t* c) {
mqtt_clean_session(c);
/* wait for mqtt thread exit */
while (c->mqtt_thread != NULL) {
}
if (CLIENT_STATE_INVALID != mqtt_get_client_state(c)) {
mqtt_clean_session(c);
}
mqtt_release(c);
platform_memory_free(c);
return 0;

View File

@ -83,8 +83,11 @@ PIKA_WEAK void platform_thread_start(platform_thread_t* thread) {
PIKA_WEAK void platform_thread_destroy(platform_thread_t* thread) {
#ifdef __linux
if (NULL != thread)
if (NULL != thread){
pthread_detach(thread->thread);
platform_memory_free(thread);
thread = NULL;
}
#elif PIKA_FREERTOS_ENABLE
if (NULL != thread)
vTaskDelete(thread->thread);

View File

@ -1612,7 +1612,12 @@ int mqtt_set_will_options(mqtt_client_t* c,
}
int mqtt_release_free(mqtt_client_t* c) {
mqtt_clean_session(c);
/* wait for mqtt thread exit */
while (c->mqtt_thread != NULL) {
}
if (CLIENT_STATE_INVALID != mqtt_get_client_state(c)) {
mqtt_clean_session(c);
}
mqtt_release(c);
platform_memory_free(c);
return 0;

View File

@ -83,8 +83,11 @@ PIKA_WEAK void platform_thread_start(platform_thread_t* thread) {
PIKA_WEAK void platform_thread_destroy(platform_thread_t* thread) {
#ifdef __linux
if (NULL != thread)
if (NULL != thread){
pthread_detach(thread->thread);
platform_memory_free(thread);
thread = NULL;
}
#elif PIKA_FREERTOS_ENABLE
if (NULL != thread)
vTaskDelete(thread->thread);