LibCore: Don't leak EventLoopImplementationUnix's ThreadData

The ThreadData still has a lifetime a longer than the thread it was
created for, but at least now it's not leaked at process exit.
This commit is contained in:
Andrew Kaster 2024-05-31 10:14:49 -06:00 committed by Andrew Kaster
parent d8103247d9
commit a9fdd819c3
Notes: sideshowbarker 2024-07-17 07:25:39 +09:00

View file

@ -26,7 +26,7 @@ namespace {
struct ThreadData;
class TimeoutSet;
HashMap<pthread_t, ThreadData*> s_thread_data;
HashMap<pthread_t, OwnPtr<ThreadData>> s_thread_data;
static pthread_rwlock_t s_thread_data_lock_impl;
static pthread_rwlock_t* s_thread_data_lock = nullptr;
thread_local pthread_t s_thread_id;
@ -228,11 +228,10 @@ struct ThreadData {
ThreadData* data = nullptr;
pthread_rwlock_rdlock(&*s_thread_data_lock);
if (!s_thread_data.contains(s_thread_id)) {
// FIXME: Don't leak this.
data = new ThreadData;
pthread_rwlock_unlock(&*s_thread_data_lock);
pthread_rwlock_wrlock(&*s_thread_data_lock);
s_thread_data.set(s_thread_id, data);
s_thread_data.set(s_thread_id, adopt_own(*data));
} else {
data = s_thread_data.get(s_thread_id).value();
}