From 31fdc64bc204c1d222dd59c7a335ba18e7ceb442 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Date: Fri, 23 Feb 2024 13:36:27 +0530 Subject: [PATCH 1/4] thread allocate/free must be done in platfom code Signed-off-by: Ajay Bhargav --- mqttclient/mqttclient.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mqttclient/mqttclient.c b/mqttclient/mqttclient.c index fc9b465..8a1ff7b 100755 --- a/mqttclient/mqttclient.c +++ b/mqttclient/mqttclient.c @@ -957,7 +957,6 @@ static void mqtt_yield_thread(void *arg) if(NULL != thread_to_be_destoried) { platform_thread_destroy(thread_to_be_destoried); - platform_memory_free(thread_to_be_destoried); thread_to_be_destoried = NULL; } } From 4caadb7836c847ffbc055592fdb9a3d4694da2ec Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Date: Fri, 23 Feb 2024 13:40:55 +0530 Subject: [PATCH 2/4] fix:RT-Thread:thread is not deleted This patch fix the issue where platform_thread_destroy do not actually delete the thread created, only memory free was done. Signed-off-by: Ajay Bhargav --- platform/RT-Thread/platform_thread.c | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/RT-Thread/platform_thread.c b/platform/RT-Thread/platform_thread.c index 1384591..acb04c5 100644 --- a/platform/RT-Thread/platform_thread.c +++ b/platform/RT-Thread/platform_thread.c @@ -59,6 +59,7 @@ void platform_thread_start(platform_thread_t* thread) void platform_thread_destroy(platform_thread_t* thread) { + rt_thread_delete(thread->thread); platform_memory_free(thread); } From c3dd408454b942bdd18d6470a47af09b511d902f Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Date: Fri, 23 Feb 2024 13:57:36 +0530 Subject: [PATCH 3/4] fix:tencentos:memory leak issue in platform_thread_destroy In tencentos implementation of platform_thread_destroy, stack size is getting freed where as stack base is suppose to be freed. platform_thread_t structure varaible is also not freed. this patch fix both the issues Signed-off-by: Ajay Bhargav --- platform/TencentOS-tiny/platform_thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/TencentOS-tiny/platform_thread.c b/platform/TencentOS-tiny/platform_thread.c index 0c45cd5..7b41f75 100644 --- a/platform/TencentOS-tiny/platform_thread.c +++ b/platform/TencentOS-tiny/platform_thread.c @@ -59,8 +59,8 @@ void platform_thread_destroy(platform_thread_t* thread) { if (NULL != thread) tos_task_destroy(&(thread->thread)); + platform_memory_free(thread->thread.stk_base); platform_memory_free(&(thread->thread)); - platform_memory_free(&(thread->thread.stk_size)); } From c869ebba0597af72838eeedb44897aaf52214e93 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Date: Fri, 23 Feb 2024 14:00:43 +0530 Subject: [PATCH 4/4] fix:linux:thread structure variable not freed on thread destroy Signed-off-by: Ajay Bhargav --- platform/linux/platform_thread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/linux/platform_thread.c b/platform/linux/platform_thread.c index 4ffc3de..3ce7433 100644 --- a/platform/linux/platform_thread.c +++ b/platform/linux/platform_thread.c @@ -54,8 +54,10 @@ void platform_thread_start(platform_thread_t* thread) void platform_thread_destroy(platform_thread_t* thread) { - if (NULL != thread) + if (NULL != thread) { pthread_detach(thread->thread); + platform_memory_free(thread); + } }