aboutsummaryrefslogtreecommitdiff
path: root/src/tcb.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-08-26 23:00:55 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-08-26 23:00:55 +0300
commit3f194f1c7264945a63b0018b159cc83bd9385c59 (patch)
tree4d277264e75b197844eae154e96e73d9cd54de3a /src/tcb.c
parent1b5a553194f47066d60bb1c9475af1f413af8f4a (diff)
downloadkmi-3f194f1c7264945a63b0018b159cc83bd9385c59.tar.gz
kmi-3f194f1c7264945a63b0018b159cc83bd9385c59.zip
fix memory leaks destroying threads
Diffstat (limited to 'src/tcb.c')
-rw-r--r--src/tcb.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/tcb.c b/src/tcb.c
index 64d95a5..43c5a94 100644
--- a/src/tcb.c
+++ b/src/tcb.c
@@ -106,6 +106,7 @@ stat_t alloc_stack(struct tcb *t)
{
/* get parent process */
struct tcb *p = get_tcb(t->eid);
+ assert(p);
t->thread_stack = __setup_thread_stack(p, thread_stack_size());
if (!t->thread_stack)
@@ -171,16 +172,33 @@ struct tcb *create_thread(struct tcb *p)
t->eid = t->pid;
t->rid = p->rid;
+ /* hmm, the rest of this function is maybe a bit too difficult to follow
+ * for my liking. Will have to think about ways to make the logic more
+ * easy to follow */
if (!(t->rpc.vmem = create_vmem())) {
- if (likely(p))
+ if (likely(p)) {
+ free_page(MM_O0, bottom);
return NULL;
+ }
+
+ destroy_vmem(t->proc.vmem);
+ free_page(MM_O0, bottom);
+ return NULL;
+ }
+
+ if (setup_rpc_stack(t)) {
+ destroy_rpc_stack(t);
+ destroy_vmem(t->rpc.vmem);
+ if (likely(p)) {
+ free_page(MM_O0, bottom);
+ return NULL;
+ }
destroy_vmem(t->proc.vmem);
free_page(MM_O0, bottom);
return NULL;
}
- setup_rpc_stack(t);
reference_thread(p);
t->regs = (vm_t)t;