From 3f194f1c7264945a63b0018b159cc83bd9385c59 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 26 Aug 2024 23:00:55 +0300 Subject: fix memory leaks destroying threads --- tests/create-exhaustion/init.c | 29 +++++++++++++++++++++++++++++ tests/create-exhaustion/source.mk | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 tests/create-exhaustion/init.c create mode 100644 tests/create-exhaustion/source.mk (limited to 'tests/create-exhaustion') diff --git a/tests/create-exhaustion/init.c b/tests/create-exhaustion/init.c new file mode 100644 index 0000000..d5ac20a --- /dev/null +++ b/tests/create-exhaustion/init.c @@ -0,0 +1,29 @@ +#include + +START(pid, tid, d0, d1, d2, d3) +{ + UNUSED(pid); + UNUSED(tid); + UNUSED(d0); + UNUSED(d1); + UNUSED(d2); + UNUSED(d3); + + size_t old_ram = 0; + while (1) { + printf("creating new thread\n"); + id_t new_thread = sys_create((uintptr_t)_start, 1, 2, 3, 4); + if (new_thread < 0) + break; + + old_ram = sys_conf_get(CONF_RAM_USAGE, 0); + } + + /* this might not be guaranteed due to how we're currently mapping the + * rpc stack, but good enough for now */ + size_t ram = sys_conf_get(CONF_RAM_USAGE, 0); + check(ram == old_ram, "'leaked' memory building thread without enough memory\n"); + + /* no crash is good enough */ + ok(); +} diff --git a/tests/create-exhaustion/source.mk b/tests/create-exhaustion/source.mk new file mode 100644 index 0000000..d096746 --- /dev/null +++ b/tests/create-exhaustion/source.mk @@ -0,0 +1,2 @@ +DO != ./scripts/gen-prog -n create-exhaustion -p init init.c +DO != ./scripts/gen-simple -n create-exhaustion -p init -- cgit v1.3