From 1da31ce8ae7a3be891e6fbf9a821ec1b5f0eb748 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 5 Jan 2020 15:11:49 +0100 Subject: [PATCH] LibCore: IDAllocator should never vend ID 0 This was tripping up CObject which interprets timer ID 0 as "no timer". Once we got ID 0 assigned, it was impossible to turn it off and it would fire on every event loop iteration, causing CPU churn. --- AK/IDAllocator.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AK/IDAllocator.h b/AK/IDAllocator.h index 406fa1ba878..51e0b2ec79c 100644 --- a/AK/IDAllocator.h +++ b/AK/IDAllocator.h @@ -16,6 +16,9 @@ public: int r = rand(); for (int i = 0; i < 100000; ++i) { int allocated_id = r + i; + // Make sure we never vend ID 0, as some code may interpret that as "no ID" + if (allocated_id == 0) + ++allocated_id; if (!m_allocated_ids.contains(allocated_id)) { m_allocated_ids.set(allocated_id); return allocated_id;