From 240961e8e88a3b3fb6624dcd89599511149f7e5c Mon Sep 17 00:00:00 2001 From: Cliff Chen Date: Fri, 15 May 2020 18:15:43 +0800 Subject: [PATCH 1/2] [Kernel] Fix double release for thread Signed-off-by: Cliff Chen --- src/thread.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/thread.c b/src/thread.c index 19ab5549c8..2b2fb1922c 100644 --- a/src/thread.c +++ b/src/thread.c @@ -338,6 +338,9 @@ rt_err_t rt_thread_detach(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread)); + if (thread->stat == RT_THREAD_CLOSE) + return RT_EOK; + if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) { /* remove from schedule */ @@ -437,6 +440,9 @@ rt_err_t rt_thread_delete(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE); + if (thread->stat == RT_THREAD_CLOSE) + return RT_EOK; + if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) { /* remove from schedule */ From 7471a665db9f5a474a066cd0f59132dac656c7e7 Mon Sep 17 00:00:00 2001 From: cliff-cmc <62226047+cliff-cmc@users.noreply.github.com> Date: Mon, 25 May 2020 08:43:13 +0800 Subject: [PATCH 2/2] Update thread.c --- src/thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thread.c b/src/thread.c index 2b2fb1922c..715596b132 100644 --- a/src/thread.c +++ b/src/thread.c @@ -338,7 +338,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread)); - if (thread->stat == RT_THREAD_CLOSE) + if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_CLOSE) return RT_EOK; if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) @@ -440,7 +440,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE); - if (thread->stat == RT_THREAD_CLOSE) + if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_CLOSE) return RT_EOK; if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT)