mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
Kernel: Process destruction should destroy all child threads.
We were only destroying the main thread when a process died, leaving any secondary threads around. They couldn't run, but because they were still in the global thread list, strange things could happen since they had some now-stale pointers to their old process.
This commit is contained in:
parent
e2cd572e60
commit
c5c4e54a67
2 changed files with 19 additions and 2 deletions
|
@ -278,7 +278,16 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
|||
|
||||
dbgprintf("%s(%d) do_exec: thread_count() = %d\n", m_name.characters(), m_pid, thread_count());
|
||||
// FIXME(Thread): Kill any threads the moment we commit to the exec().
|
||||
ASSERT(thread_count() == 1);
|
||||
if (thread_count() != 1) {
|
||||
dbgprintf("Gonna die because I have many threads! These are the threads:\n");
|
||||
for_each_thread([] (Thread& thread) {
|
||||
dbgprintf("Thread{%p}: TID=%d, PID=%d\n", &thread, thread.tid(), thread.pid());
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
ASSERT(thread_count() == 1);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
|
||||
auto parts = path.split('/');
|
||||
if (parts.is_empty())
|
||||
|
@ -605,6 +614,14 @@ Process::~Process()
|
|||
dbgprintf("~Process{%p} name=%s pid=%d, m_fds=%d\n", this, m_name.characters(), pid(), m_fds.size());
|
||||
delete m_main_thread;
|
||||
m_main_thread = nullptr;
|
||||
|
||||
Vector<Thread*, 16> my_threads;
|
||||
for_each_thread([&my_threads] (auto& thread) {
|
||||
my_threads.append(&thread);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
for (auto* thread : my_threads)
|
||||
delete thread;
|
||||
}
|
||||
|
||||
void Process::dump_regions()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue