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. *