From 292f535a6a05f160e641e256ec9d92f80514ac79 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Thu, 5 Nov 2015 22:18:49 -0800 Subject: [PATCH] Fix critical directory release refcount issue --- kernel/sys/process.c | 4 +++- userspace/tests/test-big-alloc.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 userspace/tests/test-big-alloc.c diff --git a/kernel/sys/process.c b/kernel/sys/process.c index 3d8d9573..ce9d5bed 100644 --- a/kernel/sys/process.c +++ b/kernel/sys/process.c @@ -687,11 +687,13 @@ void cleanup_process(process_t * proc, int retval) { if (proc->signal_kstack) { free(proc->signal_kstack); } + + release_directory(proc->thread.page_directory); + debug_print(INFO, "Dec'ing fds for %d", proc->id); proc->fds->refs--; if (proc->fds->refs == 0) { debug_print(INFO, "Reached 0, all dependencies are closed for %d's file descriptors and page directories", proc->id); - release_directory(proc->thread.page_directory); debug_print(INFO, "Going to clear out the file descriptors %d", proc->id); for (uint32_t i = 0; i < proc->fds->length; ++i) { if (proc->fds->entries[i]) { diff --git a/userspace/tests/test-big-alloc.c b/userspace/tests/test-big-alloc.c new file mode 100644 index 00000000..3ca3594c --- /dev/null +++ b/userspace/tests/test-big-alloc.c @@ -0,0 +1,24 @@ +#include +#include + +#include "lib/pthread.h" + +char * x; +int i; + +void *print_pid(void * garbage) { + printf("x[%d] = %d\n", i, x[i]); + pthread_exit(NULL); +} + +int main(int argc, char * argv[]) { + printf("Making a big allocation!\n"); + x = malloc(0x400000); + x[0x355555] = 'a'; + i = atoi(argv[1]); + pthread_t thread; + pthread_create(&thread, NULL, print_pid, NULL); + + waitpid(thread.id, NULL, 0); + return x[i]; +}