1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

LibGUI: Guard against use-after-free in Clipboard::the()

We now make sure that a VERIFY will fail if Clipboard::the() is called
after the destruction of its static-local variables.
This commit is contained in:
Itamar 2022-02-18 17:21:58 +02:00 committed by Andreas Kling
parent 4d2357f8f3
commit 246b42b635

View file

@ -44,6 +44,12 @@ void Clipboard::initialize(Badge<Application>)
Clipboard& Clipboard::the()
{
static bool s_destructed = false;
static ScopeGuard destructed_guard([] {
s_destructed = true;
});
VERIFY(!s_destructed); // Catch use-after-free
static Clipboard s_the;
return s_the;
}