From 333274ddfba60b5bfc19e815f2f0dcdb366271f9 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 3 Mar 2025 14:15:05 -0500 Subject: [PATCH] kernel/thread: Free death entries if they aren't used. Otherwise they will be leaked. I added a dprintf() in this codepath, it happened a small number of times on boot and when running a compile job. --- src/system/kernel/thread.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 343a9df261..64aff4d62b 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -2268,12 +2268,17 @@ thread_exit(void) } else { // The thread is not the main thread. We store a thread death entry // for it, unless someone is already waiting for it. - if (threadDeathEntry != NULL && thread->exit.waiters.IsEmpty()) { - threadDeathEntry->thread = thread->id; - threadDeathEntry->status = thread->exit.status; + if (threadDeathEntry != NULL) { + if (thread->exit.waiters.IsEmpty()) { + threadDeathEntry->thread = thread->id; + threadDeathEntry->status = thread->exit.status; - // add entry to dead thread list - team->dead_threads.Add(threadDeathEntry); + // add entry to dead thread list + team->dead_threads.Add(threadDeathEntry); + } else { + deferred_free(threadDeathEntry); + threadDeathEntry = NULL; + } } threadCreationLocker.Unlock();