Skip to content
Snippets Groups Projects
Commit 74b624af authored by Avi Kivity's avatar Avi Kivity
Browse files

sched: fix double-free of detached threads

The detached thread reaper deletes zombies, but our pthread implementation
also deletes dead pthreads (using the container object).

Fix by making the base thread use the set_cleanup() method to set up a
deleter, which is then overridden by pthreads.
parent ad357426
No related branches found
No related tags found
No related merge requests found
...@@ -295,6 +295,12 @@ thread::thread(std::function<void ()> func, attr attr, bool main) ...@@ -295,6 +295,12 @@ thread::thread(std::function<void ()> func, attr attr, bool main)
}); });
setup_tcb(); setup_tcb();
init_stack(); init_stack();
if (_attr.detached) {
// assumes detached threads directly on heap, not as member.
// if untrue, or need a special deleter, the user must call
// set_cleanup() with whatever cleanup needs to be done.
set_cleanup([=] { delete this; });
}
if (main) { if (main) {
_vruntime = 0; // simulate the first schedule into this thread _vruntime = 0; // simulate the first schedule into this thread
_status.store(status::running); _status.store(status::running);
...@@ -620,7 +626,6 @@ void thread::reaper::reap() ...@@ -620,7 +626,6 @@ void thread::reaper::reap()
auto z = _zombies.front(); auto z = _zombies.front();
_zombies.pop_front(); _zombies.pop_front();
z->join(); z->join();
delete z;
} }
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment