From 2cb5b132470217a68bc6dff1ae1c4b6154488b14 Mon Sep 17 00:00:00 2001 From: Nav Date: Thu, 17 Mar 2022 00:00:40 +0000 Subject: [PATCH] Fixed bug with TargetController attempting to release hardware that it no longer has access to. Under some circumstances, this bug was leaving the debug tool in a bad state. --- src/TargetController/TargetController.cpp | 11 ++++++----- src/TargetController/TargetController.hpp | 8 -------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/TargetController/TargetController.cpp b/src/TargetController/TargetController.cpp index e5cf529d..429f3a01 100644 --- a/src/TargetController/TargetController.cpp +++ b/src/TargetController/TargetController.cpp @@ -333,8 +333,12 @@ namespace Bloom } void TargetController::releaseHardware() { - auto target = this->getTarget(); - auto debugTool = this->getDebugTool(); + /* + * Transferring ownership of this->debugTool and this->target to this function block means if an exception is + * thrown, the objects will still be destroyed. + */ + auto debugTool = std::move(this->debugTool); + auto target = std::move(this->target); if (debugTool != nullptr && debugTool->isInitialised()) { if (target != nullptr) { @@ -349,9 +353,6 @@ namespace Bloom Logger::info("Closing debug tool"); debugTool->close(); } - - this->debugTool.reset(); - this->target.reset(); } void TargetController::loadRegisterDescriptors() { diff --git a/src/TargetController/TargetController.hpp b/src/TargetController/TargetController.hpp index 9b634c75..98f3b2d7 100644 --- a/src/TargetController/TargetController.hpp +++ b/src/TargetController/TargetController.hpp @@ -199,14 +199,6 @@ namespace Bloom return mapping; } - Targets::Target* getTarget() { - return this->target.get(); - } - - DebugTool* getDebugTool() { - return this->debugTool.get(); - } - /** * Updates the state of the TargetController and emits a state changed event. *