From e62f2f13f13bca63f05e8ce92c945dcadb0f712f Mon Sep 17 00:00:00 2001 From: arighi Date: Wed, 17 Mar 2010 11:53:06 +0000 Subject: [PATCH] Fix a memory leak in proc_freeZombies(). Evaluate the total stack size of a process as the actual stack size + the sizeo of PCB. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3217 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/kern/proc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bertos/kern/proc.c b/bertos/kern/proc.c index 794918a5..18c89599 100644 --- a/bertos/kern/proc.c +++ b/bertos/kern/proc.c @@ -60,6 +60,8 @@ #include /* memset() */ +#define PROC_SIZE_WORDS (ROUND_UP2(sizeof(Process), sizeof(cpu_stack_t)) / sizeof(cpu_stack_t)) + /* * The scheduer tracks ready processes by enqueuing them in the * ready list. @@ -163,8 +165,10 @@ static void proc_freeZombies(void) return; if (proc->flags & PF_FREESTACK) + { PROC_ATOMIC(heap_freemem(&proc_heap, proc->stack_base, - proc->stack_size)); + proc->stack_size + PROC_SIZE_WORDS * sizeof(cpu_stack_t))); + } } } @@ -206,7 +210,6 @@ static void proc_addZombie(Process *proc) struct Process *proc_new_with_name(UNUSED_ARG(const char *, name), void (*entry)(void), iptr_t data, size_t stack_size, cpu_stack_t *stack_base) { Process *proc; - const size_t PROC_SIZE_WORDS = ROUND_UP2(sizeof(Process), sizeof(cpu_stack_t)) / sizeof(cpu_stack_t); LOG_INFO("name=%s", name); #if CONFIG_KERN_HEAP bool free_stack = false; -- 2.25.1