diff --git a/src/lib/deskflow/ServerApp.cpp b/src/lib/deskflow/ServerApp.cpp index 2c22f7336..993c85230 100644 --- a/src/lib/deskflow/ServerApp.cpp +++ b/src/lib/deskflow/ServerApp.cpp @@ -516,7 +516,16 @@ int ServerApp::mainLoop() } // start server, etc - appUtil().startNode(); + try { + appUtil().startNode(); + } catch (...) { + // a fatal startup failure (e.g. the listen address is already in use) + // exits by throwing, which unwinds past the cleanup at the end of this + // function. tear the server down here so the screen and its worker + // threads don't outlive the app and call into freed globals on exit. + cleanupServer(); + throw; + } // handle hangup signal by reloading the server's configuration ARCH->setSignalHandler(Arch::ThreadSignal::Hangup, &reloadSignalHandler, nullptr); diff --git a/src/lib/platform/EiScreen.cpp b/src/lib/platform/EiScreen.cpp index 033c5e51e..db4cfadd0 100644 --- a/src/lib/platform/EiScreen.cpp +++ b/src/lib/platform/EiScreen.cpp @@ -94,6 +94,7 @@ EiScreen::~EiScreen() delete m_clipboard; delete m_portalRemoteDesktop; + delete m_portalInputCapture; } void EiScreen::eiLogEvent(ei_log_priority priority, const char *message) const