SoftwareUpdater: fix crash on exit.

Don't delete or Quit() a BWindow, it can do so by itself. Also, do not
rebuild a BMessenger everytime we want to message a window, that defeats
the purpose. There are still places where the UpdateManager calls
functions from the window object directly however, ignoring the fact
that the window may have been closed.

Fixes #13653.

Change-Id: I868e94a07d9617f343332ea00d35ffd92e60ed8e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2552
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Adrien Destugues 2020-05-02 17:11:42 +02:00 committed by waddlesplash
parent d0e1eb7a7b
commit c39f9cc827
2 changed files with 13 additions and 17 deletions

View File

@ -45,26 +45,20 @@ UpdateManager::UpdateManager(BPackageInstallationLocation location,
BPackageManager(location, &fClientInstallationInterface, this),
BPackageManager::UserInteractionHandler(),
fClientInstallationInterface(),
fStatusWindow(NULL),
fStatusWindow(new SoftwareUpdaterWindow()),
fStatusWindowMessenger(fStatusWindow),
fProblemWindow(NULL),
fProblemWindowMessenger(),
fCurrentStep(ACTION_STEP_INIT),
fChangesConfirmed(false),
fVerbose(verbose)
{
fStatusWindow = new SoftwareUpdaterWindow();
_SetCurrentStep(ACTION_STEP_START);
}
UpdateManager::~UpdateManager()
{
if (fStatusWindow != NULL) {
fStatusWindow->Lock();
fStatusWindow->Quit();
}
if (fProblemWindow != NULL) {
fProblemWindow->Lock();
fProblemWindow->Quit();
}
}
@ -92,11 +86,10 @@ update_type
UpdateManager::GetUpdateType()
{
int32 action = USER_SELECTION_NEEDED;
BMessenger messenger(fStatusWindow);
if (messenger.IsValid()) {
if (fStatusWindowMessenger.IsValid()) {
BMessage message(kMsgGetUpdateType);
BMessage reply;
messenger.SendMessage(&message, &reply);
fStatusWindowMessenger.SendMessage(&message, &reply);
reply.FindInt32(kKeyAlertResult, &action);
}
return (update_type)action;
@ -110,11 +103,10 @@ UpdateManager::CheckRepositories()
if (fVerbose)
printf("Remote repositories available: %" B_PRId32 "\n", count);
if (count == 0) {
BMessenger messenger(fStatusWindow);
if (messenger.IsValid()) {
if (fStatusWindowMessenger.IsValid()) {
BMessage message(kMsgNoRepositories);
BMessage reply;
messenger.SendMessage(&message, &reply);
fStatusWindowMessenger.SendMessage(&message, &reply);
int32 result;
reply.FindInt32(kKeyAlertResult, &result);
if (result == 1)
@ -159,8 +151,10 @@ UpdateManager::FinalUpdate(const char* header, const char* text)
void
UpdateManager::HandleProblems()
{
if (fProblemWindow == NULL)
if (fProblemWindow == NULL) {
fProblemWindow = new ProblemWindow;
fProblemWindowMessenger.SetTo(fProblemWindow);
}
ProblemWindow::SolverPackageSet installPackages;
ProblemWindow::SolverPackageSet uninstallPackages;

View File

@ -88,7 +88,9 @@ private:
fClientInstallationInterface;
SoftwareUpdaterWindow* fStatusWindow;
BMessenger fStatusWindowMessenger;
ProblemWindow* fProblemWindow;
BMessenger fProblemWindowMessenger;
uint32 fCurrentStep;
bool fChangesConfirmed;
bool fNewDownloadStarted;