diff -Nru wxmaxima-21.01.0/debian/changelog wxmaxima-21.01.0/debian/changelog --- wxmaxima-21.01.0/debian/changelog 2021-04-01 12:33:10.000000000 +0000 +++ wxmaxima-21.01.0/debian/changelog 2021-04-03 06:33:42.000000000 +0000 @@ -1,8 +1,8 @@ -wxmaxima (21.01.0-27~202104010510~ubuntu21.04.1) hirsute; urgency=low +wxmaxima (21.01.0-27~202104030352~ubuntu21.04.1) hirsute; urgency=low * Auto build. - -- Launchpad Package Builder Thu, 01 Apr 2021 12:33:10 +0000 + -- Launchpad Package Builder Sat, 03 Apr 2021 06:33:42 +0000 wxmaxima (21.01.0-1) unstable; urgency=medium diff -Nru wxmaxima-21.01.0/debian/git-build-recipe.manifest wxmaxima-21.01.0/debian/git-build-recipe.manifest --- wxmaxima-21.01.0/debian/git-build-recipe.manifest 2021-04-01 12:33:10.000000000 +0000 +++ wxmaxima-21.01.0/debian/git-build-recipe.manifest 2021-04-03 06:33:42.000000000 +0000 @@ -1,3 +1,3 @@ -# git-build-recipe format 0.4 deb-version {debupstream}-27~202104010510 -lp:wxmaxima git-commit:e8aab6b32effb45ed03c9f740dc5c42e052ab65a +# git-build-recipe format 0.4 deb-version {debupstream}-27~202104030352 +lp:wxmaxima git-commit:fe850c816221b52e639518ab9cf7856d409a0b4d merge packaging lp:wxmaxima git-commit:c2873988f0860cd31b0038baebf45f7f0baa62c5 diff -Nru wxmaxima-21.01.0/src/wxMaxima.cpp wxmaxima-21.01.0/src/wxMaxima.cpp --- wxmaxima-21.01.0/src/wxMaxima.cpp 2021-04-01 12:33:09.000000000 +0000 +++ wxmaxima-21.01.0/src/wxMaxima.cpp 2021-04-03 06:33:41.000000000 +0000 @@ -235,8 +235,8 @@ } // Needed for making wxSocket work for multiple threads. We currently don't - // use this feature. - // wxSocketBase::Initialize(); + // use this feature. But it doesn't harm to be prepared + wxSocketBase::Initialize(); // Will be corrected by ConfigChanged() m_maxOutputCellsPerCommand = -1; @@ -277,8 +277,6 @@ m_first = true; m_dispReadOut = false; - m_server = NULL; - config->Read(wxT("lastPath"), &m_lastPath); m_lastPrompt = wxEmptyString; @@ -315,34 +313,10 @@ m_statusBar->GetNetworkStatusElement()->Connect(wxEVT_LEFT_DCLICK, wxCommandEventHandler(wxMaxima::NetworkDClick), NULL, this); - bool server = false; - m_port = m_worksheet->m_configuration->DefaultPort(); - while (!(server = StartServer())) - { - wxLogMessage( - wxString::Format( - _("Trying to start a server on port %i instead"),m_port)); - m_port++; - if ((m_port > m_worksheet->m_configuration->DefaultPort() + 15000) || (m_port > 65535)) - { - LoggingMessageBox(_("wxMaxima could not start the server.\n\n" - "Please check you have network support\n" - "enabled and try again!"), - _("Fatal error"), - wxOK | wxICON_ERROR); - break; - } - } - - if (!server) - LeftStatusText(_("Starting server failed")); - else + if(m_openFile.IsEmpty()) { - if(m_openFile.IsEmpty()) - { - if (!StartMaxima()) - LeftStatusText(_("Starting Maxima process failed")); - } + if (!StartMaxima()) + LeftStatusText(_("Starting Maxima process failed")); } Connect(wxEVT_SCROLL_CHANGED, wxScrollEventHandler(wxMaxima::SliderEvent), NULL, this); @@ -1188,11 +1162,6 @@ wxMaxima::~wxMaxima() { - if(m_server) - { - m_server->Destroy(); - m_server = NULL; - } KillMaxima(false); MyApp::DelistTopLevelWindow(this); @@ -1738,35 +1707,55 @@ bool wxMaxima::StartServer() { - if(m_server) - { - m_server->Destroy(); - m_server = NULL; - } - - RightStatusText(wxString::Format(_("Starting server on port %d"), m_port)); + if ((m_server) && (m_server->IsOk())) + return true; - wxIPV4address addr; - if(!addr.AnyAddress()) - wxLogMessage(_("Cannot set the communication address to localhost.")); - if(!addr.Service(m_port)) - wxLogMessage(wxString::Format(_("Cannot set the communication port to %i."), m_port)); + if (m_server) + m_server.reset(); + + m_port = m_worksheet->m_configuration->DefaultPort(); - m_server = new wxSocketServer(addr); - if (!m_server->IsOk()) + do + { + wxLogMessage( + wxString::Format( + _("Trying to start the socket a maxima on the local machine can connect to on port %i"), + m_port)); + wxIPV4address addr; + if(!addr.AnyAddress()) + wxLogMessage(_("Cannot set the communication address to localhost.")); + if(!addr.Service(m_port)) + wxLogMessage(wxString::Format(_("Cannot set the communication port to %i."), m_port)); + m_server = std::unique_ptr (new wxSocketServer(addr)); + if(!m_server->IsOk()) + { + m_port++; + m_server.reset(); + } + } while(((m_port < m_worksheet->m_configuration->DefaultPort() + 15000) && (m_port < 65535) && + (!m_server))); + + if (!m_server) { - m_server->Destroy(); - m_server = NULL; RightStatusText(_("Starting server failed")); m_statusBar->NetworkStatus(StatusBar::error); + LoggingMessageBox(_("wxMaxima could not start a server.\n\n" + "Please check you have network support\n" + "enabled and try again!"), + _("Fatal error"), + wxOK | wxICON_ERROR); + return false; } - m_server->SetEventHandler(*GetEventHandler()); - m_server->Notify(true); - m_server->SetNotify(wxSOCKET_CONNECTION_FLAG); - m_server->SetTimeout(30); - RightStatusText(_("Server started")); - return true; + else + { + m_server->SetEventHandler(*GetEventHandler()); + m_server->Notify(true); + m_server->SetNotify(wxSOCKET_CONNECTION_FLAG); + m_server->SetTimeout(30); + RightStatusText(_("Server started")); + return true; + } } ///-------------------------------------------------------------------------------- @@ -1775,9 +1764,7 @@ bool wxMaxima::StartMaxima(bool force) { - StartServer(); - // cppcheck-suppress duplicateCondition - if(!m_server) + if(!StartServer()) return false; wxString dirname; diff -Nru wxmaxima-21.01.0/src/wxMaxima.h wxmaxima-21.01.0/src/wxMaxima.h --- wxmaxima-21.01.0/src/wxMaxima.h 2021-04-01 12:33:09.000000000 +0000 +++ wxmaxima-21.01.0/src/wxMaxima.h 2021-04-03 06:33:41.000000000 +0000 @@ -641,7 +641,25 @@ } std::unique_ptr m_client; - wxSocketServer *m_server; + /*! The Right Way to delete a wxSocketServer + + The destructor might delete the server before all pending server events have been + processed which leads to a crash. + */ + struct ServerDeleter { + void operator()(wxSocketServer* server) const { + server->Close(); + wxLogMessage(_("Closing the socket maxima could connect to!")); + server->Destroy(); + } +}; + /*! The server maxima connects to as client + + The destructor of the server causes + crashes if there are still pending events. + Instead we need to call destroy. + */ + std::unique_ptr m_server; wxProcess *m_process; //! The stdout of the maxima process