From 6d4d2fe7fc4a0d2c70b64d9c232ef2758dd8bf80 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Thu, 6 Jan 2022 23:58:41 -0800 Subject: Fix memory leak --- src/sys/core.c | 10 ++++------ src/sys/schedule.c | 7 ++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/sys/core.c b/src/sys/core.c index 384add5..e590e5c 100644 --- a/src/sys/core.c +++ b/src/sys/core.c @@ -59,11 +59,10 @@ void sysinit(void) add_thread(testlocal, 0); add_thread(testlocal, 1); add_thread(testlocal, 3); - add_thread(testlocal, 0); - add_thread(testlocal, 5); - add_thread(testlocal, 8); //delay(0x20000000); schedule(); + heap_info(); + sched_info(); } struct Mutex testm = {.addr = (void*)0xDEADBEEF, .pid = NULL_PID}; @@ -82,6 +81,7 @@ void testlocal1(void) uart_10(a); uart_string(" Done!\n"); } + void testlocal(void) { struct Thread* t = scheduler.rthread_ll->data; @@ -91,9 +91,7 @@ void testlocal(void) uart_10(t->data.priority); uart_string(" ...\n"); //delay(0x80000000); - if (t->data.pid == 6) { - add_thread(testlocal, 0); - } else if (t->data.pid == 5) { + if (t->data.pid == 5) { add_thread(testlocal1, 1); schedule(); } diff --git a/src/sys/schedule.c b/src/sys/schedule.c index 7dc2205..ac5b3e2 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -139,9 +139,9 @@ void cleanup(void) if (scheduler.rthread_ll != 0) { // Mark the thread as finished struct Thread* t = scheduler.rthread_ll->data; - uart_string("Cleaning up thread "); - uart_10(t->data.pid); - uart_char('\n'); + //uart_string("Cleaning up thread "); + //uart_10(t->data.pid); + //uart_char('\n'); t->data.status = THREAD_FINISHED; // Mark the stack space as free unsigned long sidx = (unsigned long)(heap_end() - t->stack_base)/STACK_SIZE; @@ -152,6 +152,7 @@ void cleanup(void) struct LL* next = ll->next; prev->next = ll->next; next->prev = ll->prev; + free(ll->data); free(ll); scheduler.rthread_ll = 0; } -- cgit v1.2.1