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
commit 246b42b635
Notes: sideshowbarker 2024-07-17 18:33:02 +09:00

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;
}