mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-01 16:02:53 +00:00
LibCore: Fix some thread-related memory/object leaks
This commit is contained in:
parent
9171c35183
commit
920f470735
Notes:
sideshowbarker
2024-07-17 06:51:48 +09:00
Author: https://github.com/alimpfard
Commit: 920f470735
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/213
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/awesomekling
2 changed files with 34 additions and 12 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <LibCore/ThreadEventQueue.h>
|
||||
#include <LibThreading/Mutex.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
@ -39,15 +40,24 @@ struct ThreadEventQueue::Private {
|
|||
bool warned_promise_count { false };
|
||||
};
|
||||
|
||||
static thread_local ThreadEventQueue* s_current_thread_event_queue;
|
||||
static pthread_key_t s_current_thread_event_queue_key;
|
||||
static pthread_once_t s_current_thread_event_queue_key_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
ThreadEventQueue& ThreadEventQueue::current()
|
||||
{
|
||||
if (!s_current_thread_event_queue) {
|
||||
// FIXME: Don't leak these.
|
||||
s_current_thread_event_queue = new ThreadEventQueue;
|
||||
pthread_once(&s_current_thread_event_queue_key_once, [] {
|
||||
pthread_key_create(&s_current_thread_event_queue_key, [](void* value) {
|
||||
if (value)
|
||||
delete static_cast<ThreadEventQueue*>(value);
|
||||
});
|
||||
});
|
||||
|
||||
auto* ptr = static_cast<ThreadEventQueue*>(pthread_getspecific(s_current_thread_event_queue_key));
|
||||
if (!ptr) {
|
||||
ptr = new ThreadEventQueue;
|
||||
pthread_setspecific(s_current_thread_event_queue_key, ptr);
|
||||
}
|
||||
return *s_current_thread_event_queue;
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
ThreadEventQueue::ThreadEventQueue()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue