Skip to content

Commit

Permalink
sched: free up old thread's memory in exec()
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Oct 6, 2024
1 parent fe1d55e commit c2a72f8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sched/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c2a72f8

Please sign in to comment.