2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 14:17:45 +00:00

Ensure Wayland integration instance accessor doesn't leak

This commit is contained in:
Ilya Fedin
2023-06-16 11:59:40 +04:00
committed by John Preston
parent c9179b78b3
commit a3cdf19c1f
3 changed files with 11 additions and 8 deletions

View File

@@ -123,12 +123,15 @@ WaylandIntegration::~WaylandIntegration() = default;
WaylandIntegration *WaylandIntegration::Instance() {
if (!IsWayland()) return nullptr;
static std::optional<WaylandIntegration> instance(std::in_place);
[[maybe_unused]] static const auto Inited = [] {
base::qt_signal_producer(
QGuiApplication::platformNativeInterface(),
&QObject::destroyed
) | rpl::start_with_next([&] {
) | rpl::start_with_next([] {
instance = std::nullopt;
}, instance->_private->lifetime);
return true;
}();
if (!instance) return nullptr;
return &*instance;
}