Skip to content

Commit a9349af

Browse files
committed
Merge branch 'memory_free_issue'
2 parents b441ab9 + 2a54863 commit a9349af

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

mqttclient/mqttclient.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,6 @@ static void mqtt_yield_thread(void *arg)
957957
if(NULL != thread_to_be_destoried)
958958
{
959959
platform_thread_destroy(thread_to_be_destoried);
960-
platform_memory_free(thread_to_be_destoried);
961960
thread_to_be_destoried = NULL;
962961
}
963962
}

platform/FreeRTOS/platform_thread.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ platform_thread_t *platform_thread_init( const char *name,
1717
{
1818
BaseType_t err;
1919
platform_thread_t *thread;
20-
20+
2121
thread = platform_memory_alloc(sizeof(platform_thread_t));
2222

2323
(void)tick;
@@ -50,10 +50,11 @@ void platform_thread_start(platform_thread_t* thread)
5050

5151
void platform_thread_destroy(platform_thread_t* thread)
5252
{
53-
if (NULL != thread)
54-
vTaskDelete(thread->thread);
55-
56-
platform_memory_free(thread);
57-
}
53+
if (NULL != thread) {
54+
TaskHandle_t thread_handle = thread->thread;
5855

56+
platform_memory_free(thread);
5957

58+
vTaskDelete(thread_handle);
59+
}
60+
}

platform/RT-Thread/platform_thread.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ platform_thread_t *platform_thread_init( const char *name,
2828
thread->thread = rt_thread_create((const char *)name,
2929
entry, param,
3030
stack_size, priority, tick);
31-
31+
3232
if (thread->thread == RT_NULL)
3333
{
34-
return RT_NULL;
34+
return RT_NULL;
3535
}
3636
else
3737
{
38-
return thread;
38+
return thread;
3939
}
4040

4141
}
@@ -49,7 +49,6 @@ void platform_thread_startup(platform_thread_t* thread)
4949
void platform_thread_stop(platform_thread_t* thread)
5050
{
5151
rt_thread_suspend(thread->thread);
52-
5352
}
5453

5554
void platform_thread_start(platform_thread_t* thread)
@@ -59,7 +58,9 @@ void platform_thread_start(platform_thread_t* thread)
5958

6059
void platform_thread_destroy(platform_thread_t* thread)
6160
{
62-
platform_memory_free(thread);
61+
if (thread) {
62+
rt_thread_t thread_handle = thread->thread;
63+
platform_memory_free(thread);
64+
rt_thread_delete(thread_handle);
65+
}
6366
}
64-
65-

platform/TencentOS-tiny/platform_thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ void platform_thread_destroy(platform_thread_t* thread)
5959
{
6060
if (NULL != thread)
6161
tos_task_destroy(&(thread->thread));
62+
platform_memory_free(thread->thread.stk_base);
6263
platform_memory_free(&(thread->thread));
63-
platform_memory_free(&(thread->thread.stk_size));
6464
}
6565

6666

platform/linux/platform_thread.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ void platform_thread_start(platform_thread_t* thread)
5454

5555
void platform_thread_destroy(platform_thread_t* thread)
5656
{
57-
if (NULL != thread)
57+
if (NULL != thread) {
5858
pthread_detach(thread->thread);
59+
platform_memory_free(thread);
60+
}
5961
}
6062

6163

0 commit comments

Comments
 (0)