Skip to content

Commit

Permalink
LibCore: Don't leak EventLoopImplementationUnix's ThreadData
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ADKaster committed May 31, 2024
1 parent 21d8efb commit 9096ab6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 9096ab6

Please sign in to comment.