From 54eeb8ee9a57850aca5056a5834bfb86a210bf1a Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 29 Dec 2020 13:14:21 -0700 Subject: AK: Fix a race condition with WeakPtr::strong_ref and destruction Since RefPtr decrements the ref counter to 0 and after that starts destructing the object, there is a window where the ref count is 0 and the weak references have not been revoked. Also change WeakLink to be able to obtain a strong reference concurrently and block revoking instead, which should happen a lot less often. Fixes a problem observed in #4621 --- Libraries/LibGUI/Application.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Libraries/LibGUI') diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp index a70e7d5b39..55cc9373c9 100644 --- a/Libraries/LibGUI/Application.cpp +++ b/Libraries/LibGUI/Application.cpp @@ -72,6 +72,11 @@ static NeverDestroyed> s_the; Application* Application::the() { + // NOTE: If we don't explicitly call revoke_weak_ptrs() in the + // ~Application destructor, we would have to change this to + // return s_the->strong_ref().ptr(); + // This is because this is using the unsafe operator*/operator-> + // that do not have the ability to check the ref count! return *s_the; } -- cgit v1.2.3