From c2a72f845bf1dc14bc916bef7c2dc68809df4309 Mon Sep 17 00:00:00 2001 From: jewelcodes Date: Sun, 6 Oct 2024 03:19:48 -0400 Subject: [PATCH] sched: free up old thread's memory in exec() --- src/sched/exec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sched/exec.c b/src/sched/exec.c index ca59771..54b7b92 100644 --- a/src/sched/exec.c +++ b/src/sched/exec.c @@ -276,6 +276,8 @@ int execrdv(Thread *t, const char *name, const char **argv) { int execmve(Thread *t, void *image, const char **argv, const char **envp) { // create the new context before deleting the current one // this guarantees we can return on failure + uint64_t oldHighest = t->highest; + void *newctx = calloc(1, PLATFORM_CONTEXT_SIZE); if(!newctx) { return -1; @@ -323,6 +325,7 @@ int execmve(Thread *t, void *image, const char **argv, const char **envp) { // TODO: here we've successfully loaded the new program, but we also need // to free up memory used by the original program + platformCleanThread(oldctx, oldHighest); free(oldctx); t->status = THREAD_QUEUED;