aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-11-23 20:26:17 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-11-23 20:26:17 +0000
commitd973c3f25a6ab56e12b9f858b0692ec4297d84c9 (patch)
tree3a28d4ddb63bd852867237ca6bfd8e013a5663b7 /os/kernel/src
parenta5bdf86e5b89a7abb281ac5514c7d6cb4d64c365 (diff)
downloadChibiOS-d973c3f25a6ab56e12b9f858b0692ec4297d84c9.tar.gz
ChibiOS-d973c3f25a6ab56e12b9f858b0692ec4297d84c9.tar.bz2
ChibiOS-d973c3f25a6ab56e12b9f858b0692ec4297d84c9.zip
Fixed bug 3116888.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2425 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/kernel/src')
-rw-r--r--os/kernel/src/chdynamic.c13
-rw-r--r--os/kernel/src/chthreads.c5
2 files changed, 14 insertions, 4 deletions
diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c
index 06e5bd00a..5f1fc3401 100644
--- a/os/kernel/src/chdynamic.c
+++ b/os/kernel/src/chdynamic.c
@@ -71,17 +71,24 @@ void chThdRelease(Thread *tp) {
refs = --tp->p_refs;
chSysUnlock();
- /* If the references counter reaches zero then the memory can be returned
- to the proper allocator. Of course static threads are not affected.*/
- if (refs == 0) {
+ /* If the references counter reaches zero and the thread is in its
+ terminated state then the memory can be returned to the proper
+ allocator. Of course static threads are not affected.*/
+ if ((refs == 0) && (tp->p_state == THD_STATE_FINAL)) {
switch (tp->p_flags & THD_MEM_MODE_MASK) {
#if CH_USE_HEAP
case THD_MEM_MODE_HEAP:
+#if CH_USE_REGISTRY
+ REG_REMOVE(tp);
+#endif
chHeapFree(tp);
break;
#endif
#if CH_USE_MEMPOOLS
case THD_MEM_MODE_MEMPOOL:
+#if CH_USE_REGISTRY
+ REG_REMOVE(tp);
+#endif
chPoolFree(tp->p_mpool, tp);
break;
#endif
diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c
index 4e8ae1c21..ced8a77e0 100644
--- a/os/kernel/src/chthreads.c
+++ b/os/kernel/src/chthreads.c
@@ -342,7 +342,10 @@ void chThdExit(msg_t msg) {
chSchReadyI(list_remove(&tp->p_waiting));
#endif
#if CH_USE_REGISTRY
- REG_REMOVE(tp);
+ /* Static threads are immediately removed from the registry because
+ there is no memory to recover.*/
+ if ((tp->p_flags & THD_MEM_MODE_MASK) == THD_MEM_MODE_STATIC)
+ REG_REMOVE(tp);
#endif
chSchGoSleepS(THD_STATE_FINAL);
}