Debugger: Fix crash in teams window.

- Some of the recent changes for memory management exposed a race
  condition, where the teams window would potentially try to access
  already freed objects on quit. Ensure we acquire references to the target
  host so this doesn't happen.
This commit is contained in:
Rene Gollent
2018-01-13 15:36:22 -05:00
parent 813b6c656f
commit 7082366900
2 changed files with 15 additions and 9 deletions
@@ -1,6 +1,6 @@
/*
* Copyright 2009-2010, Philippe Houdoin, [email protected]. All rights reserved.
* Copyright 2013, Rene Gollent, [email protected].
* Copyright 2013-2018, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
@@ -277,7 +277,8 @@ TeamsListView::TeamsListView(const char* name)
Inherited(name, B_NAVIGABLE, B_PLAIN_BORDER),
TargetHost::Listener(),
TeamsWindow::Listener(),
fInterface(NULL)
fInterface(NULL),
fHost(NULL)
{
AddColumn(new TeamsColumn("Name", 400, 100, 600,
B_TRUNCATE_BEGINNING), kNameColumn);
@@ -289,6 +290,8 @@ TeamsListView::TeamsListView(const char* name)
TeamsListView::~TeamsListView()
{
if (fHost != NULL)
fHost->ReleaseReference();
}
@@ -435,10 +438,8 @@ TeamsListView::SelectedInterfaceChanged(TargetHostInterface* interface)
void
TeamsListView::_InitList()
{
TargetHost* host = fInterface->GetTargetHost();
AutoLocker<TargetHost> hostLocker(host);
for (int32 i = 0; i < host->CountTeams(); i++) {
TeamInfo* info = host->TeamInfoAt(i);
AutoLocker<TargetHost> hostLocker(fHost);
for (int32 i = 0; TeamInfo* info = fHost->TeamInfoAt(i); i++) {
BRow* row = new TeamRow(info);
AddRow(row);
}
@@ -453,13 +454,17 @@ TeamsListView::_SetInterface(TargetHostInterface* interface)
if (fInterface != NULL) {
Clear();
fInterface->GetTargetHost()->RemoveListener(this);
fHost->RemoveListener(this);
fHost->ReleaseReference();
fHost = NULL;
}
fInterface = interface;
if (fInterface == NULL)
return;
fInterface->GetTargetHost()->AddListener(this);
fHost = fInterface->GetTargetHost();
fHost->AcquireReference();
fHost->AddListener(this);
_InitList();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2016, Haiku Inc. All rights reserved.
* Copyright 2009-2018, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
@@ -120,6 +120,7 @@ private:
private:
TargetHostInterface* fInterface;
TargetHost* fHost;
};