summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAlex Muscar <src@muscar.eu>2020-03-10 10:31:37 +0000
committerGitHub <noreply@github.com>2020-03-10 11:31:37 +0100
commit81c6f72134ed0f955792cece46c5073773a769a5 (patch)
tree1a00693a0abb1fd68ca4d5afad5a84b93e194066 /Libraries
parente07f50c39860ec006a7110dc13ea7001a6a54fc9 (diff)
downloadserenity-81c6f72134ed0f955792cece46c5073773a769a5.zip
EventLoop: Don't destroy ID allocator (#1403)
The ID allocator is destroyed before a timer in HackStudio is is unregistered leading to an access violation. Fixes #1382.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibCore/EventLoop.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/Libraries/LibCore/EventLoop.cpp b/Libraries/LibCore/EventLoop.cpp
index c79f73e7a4..ff413b8d21 100644
--- a/Libraries/LibCore/EventLoop.cpp
+++ b/Libraries/LibCore/EventLoop.cpp
@@ -28,6 +28,7 @@
#include <AK/IDAllocator.h>
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
+#include <AK/NeverDestroyed.h>
#include <AK/Time.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
@@ -73,7 +74,7 @@ struct EventLoop::Private {
static EventLoop* s_main_event_loop;
static Vector<EventLoop*>* s_event_loop_stack;
-static IDAllocator s_id_allocator;
+static NeverDestroyed<IDAllocator> s_id_allocator;
static HashMap<int, NonnullOwnPtr<EventLoopTimer>>* s_timers;
static HashTable<Notifier*>* s_notifiers;
int EventLoop::s_wake_pipe_fds[2];
@@ -85,7 +86,7 @@ class RPCClient : public Object {
public:
explicit RPCClient(RefPtr<LocalSocket> socket)
: m_socket(move(socket))
- , m_client_id(s_id_allocator.allocate())
+ , m_client_id(s_id_allocator->allocate())
{
s_rpc_clients.set(m_client_id, this);
add_child(*m_socket);
@@ -201,7 +202,7 @@ public:
void shutdown()
{
s_rpc_clients.remove(m_client_id);
- s_id_allocator.deallocate(m_client_id);
+ s_id_allocator->deallocate(m_client_id);
}
private:
@@ -524,7 +525,7 @@ int EventLoop::register_timer(Object& object, int milliseconds, bool should_relo
timer->reload(now);
timer->should_reload = should_reload;
timer->fire_when_not_visible = fire_when_not_visible;
- int timer_id = s_id_allocator.allocate();
+ int timer_id = s_id_allocator->allocate();
timer->timer_id = timer_id;
s_timers->set(timer_id, move(timer));
return timer_id;
@@ -532,7 +533,7 @@ int EventLoop::register_timer(Object& object, int milliseconds, bool should_relo
bool EventLoop::unregister_timer(int timer_id)
{
- s_id_allocator.deallocate(timer_id);
+ s_id_allocator->deallocate(timer_id);
auto it = s_timers->find(timer_id);
if (it == s_timers->end())
return false;