mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 11:55:07 +00:00
AK: Fix a race condition with WeakPtr<T>::strong_ref and destruction
Since RefPtr<T> 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
This commit is contained in:
parent
3e00e3da72
commit
54eeb8ee9a
4 changed files with 88 additions and 24 deletions
|
@ -72,6 +72,11 @@ static NeverDestroyed<WeakPtr<Application>> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue