From 318673e7646796d55426c90b206abbd9d8253bf3 Mon Sep 17 00:00:00 2001 From: matjam Date: Mon, 9 Mar 2026 14:45:23 -0700 Subject: protocols/sessionLock: fix crash when monitor is gone during lock surface creation Move monitor signal listener registration inside the existing null guard, and validate output resource and monitor in onGetLockSurface. --- src/protocols/SessionLock.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/protocols/SessionLock.cpp') diff --git a/src/protocols/SessionLock.cpp b/src/protocols/SessionLock.cpp index 88231f38..de2b96f2 100644 --- a/src/protocols/SessionLock.cpp +++ b/src/protocols/SessionLock.cpp @@ -62,11 +62,11 @@ CSessionLockSurface::CSessionLockSurface(SP resource_, if (m_surface) m_surface->enter(m_monitor.lock()); + + m_listeners.monitorMode = m_monitor->m_events.modeChanged.listen([this] { sendConfigure(); }); } sendConfigure(); - - m_listeners.monitorMode = m_monitor->m_events.modeChanged.listen([this] { sendConfigure(); }); } CSessionLockSurface::~CSessionLockSurface() { @@ -203,8 +203,17 @@ void CSessionLockProtocol::onLock(CExtSessionLockManagerV1* pMgr, uint32_t id) { void CSessionLockProtocol::onGetLockSurface(CExtSessionLockV1* lock, uint32_t id, wl_resource* surface, wl_resource* output) { LOGM(Log::DEBUG, "New sessionLockSurface with id {}", id); - auto PSURFACE = CWLSurfaceResource::fromResource(surface); - auto PMONITOR = CWLOutputResource::fromResource(output)->m_monitor.lock(); + auto PSURFACE = CWLSurfaceResource::fromResource(surface); + auto OUTPUTRES = CWLOutputResource::fromResource(output); + if (!OUTPUTRES) { + LOGM(Log::ERR, "onGetLockSurface: invalid output resource"); + return; + } + auto PMONITOR = OUTPUTRES->m_monitor.lock(); + if (!PMONITOR) { + LOGM(Log::ERR, "onGetLockSurface: monitor is gone for output resource"); + return; + } SP sessionLock; for (auto const& l : m_locks) { -- cgit v1.2.3