From 7082366900e8ad430470fbaa105d687b42d630fd Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sat, 13 Jan 2018 15:36:22 -0500 Subject: [PATCH] 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. --- .../gui/teams_window/TeamsListView.cpp | 21 ++++++++++++------- .../gui/teams_window/TeamsListView.h | 3 ++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/teams_window/TeamsListView.cpp b/src/apps/debugger/user_interface/gui/teams_window/TeamsListView.cpp index 39b46a9c35..b95ad45436 100644 --- a/src/apps/debugger/user_interface/gui/teams_window/TeamsListView.cpp +++ b/src/apps/debugger/user_interface/gui/teams_window/TeamsListView.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009-2010, Philippe Houdoin, phoudoin@haiku-os.org. All rights reserved. - * Copyright 2013, Rene Gollent, rene@gollent.com. + * Copyright 2013-2018, Rene Gollent, rene@gollent.com. * 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 hostLocker(host); - for (int32 i = 0; i < host->CountTeams(); i++) { - TeamInfo* info = host->TeamInfoAt(i); + AutoLocker 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(); } diff --git a/src/apps/debugger/user_interface/gui/teams_window/TeamsListView.h b/src/apps/debugger/user_interface/gui/teams_window/TeamsListView.h index 73d8e0be28..5ad4cffd7c 100644 --- a/src/apps/debugger/user_interface/gui/teams_window/TeamsListView.h +++ b/src/apps/debugger/user_interface/gui/teams_window/TeamsListView.h @@ -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; };