mirror of
https://github.com/hyprwm/Hyprland
synced 2026-05-07 14:18:30 +02:00
screenshare: adjust session cleanup and event emission order (#14229)
* fix(screenshare): adjust session cleanup and event emission order Revised the handling of `stoppedListener` initialization in `getManagedSession` to ensure correct scoping and lifecycle management. Updated the `stop` method in `CScreenshareSession` to adjust the order of `screenshareEvents` and `stopped.emit()` to prevent potential use-after-free scenarios. * fix(screenshare): ensure managedSession removal uses consistent target reference This change updates the lambda in the stopped listener to use a pre-fetched target pointer for comparison when erasing sessions. * fix(screenshare): use early-return and smart ptr comparison in session cleanup
This commit is contained in:
parent
5f9df52b55
commit
4ab3a40398
2 changed files with 11 additions and 9 deletions
|
|
@ -140,16 +140,18 @@ WP<CScreenshareSession> CScreenshareManager::getManagedSession(eScreenshareType
|
|||
m_sessions.emplace_back(session);
|
||||
|
||||
it = m_managedSessions.emplace(m_managedSessions.end(), makeUnique<SManagedSession>(std::move(session)));
|
||||
|
||||
auto& managed = *it;
|
||||
managed->stoppedListener = managed->m_session->m_events.stopped.listen([managed = WP<SManagedSession>(managed)]() {
|
||||
if (!managed)
|
||||
return;
|
||||
|
||||
const auto& session = managed->m_session;
|
||||
std::erase_if(Screenshare::mgr()->m_managedSessions, [&session](const auto& s) { return s && s->m_session == session; });
|
||||
});
|
||||
}
|
||||
|
||||
auto& session = *it;
|
||||
|
||||
session->stoppedListener = session->m_session->m_events.stopped.listen([session = WP<SManagedSession>(session)]() {
|
||||
if (!session.expired())
|
||||
std::erase_if(Screenshare::mgr()->m_managedSessions, [&](const auto& s) { return s && s->m_session.get() == session->m_session.get(); });
|
||||
});
|
||||
|
||||
return session->m_session;
|
||||
return (*it)->m_session;
|
||||
}
|
||||
|
||||
bool CScreenshareManager::isOutputBeingSSd(PHLMONITOR monitor) {
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ void CScreenshareSession::stop() {
|
|||
if (m_stopped)
|
||||
return;
|
||||
m_stopped = true;
|
||||
m_events.stopped.emit();
|
||||
|
||||
screenshareEvents(false);
|
||||
m_events.stopped.emit();
|
||||
}
|
||||
|
||||
bool CScreenshareSession::isActive() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue