Truly independent web browser
LibGC: Release a block allocator only under its lock in the worker
sideshowbarker6893796043bc
diff --git a/Libraries/LibGC/BlockAllocator.cpp b/Libraries/LibGC/BlockAllocator.cppindex 37fb6394903..7789d67a98c 100644--- a/Libraries/LibGC/BlockAllocator.cpp+++ b/Libraries/LibGC/BlockAllocator.cpp@@ -432,11 +432,11 @@ void DecommitWorker::run()for (auto* a : snapshot) {process_one(*a, return_cold_blocks);- int prev_refcount = a->m_worker_refcount.fetch_sub(1);- if (prev_refcount == 1) {- MutexLocker locker(a->m_mutex);+ // The count drops under the allocator's lock, so its destructor can't see the count reach zero, and destroy+ // the lock, before this thread is done with the lock.+ MutexLocker locker(a->m_mutex);+ if (a->m_worker_refcount.fetch_sub(1) == 1)a->m_worker_cv.broadcast();- }}}}