From 87cb6a2cba32094e47a80a4e3b89594628cdeae5 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sat, 18 Sep 2021 21:35:30 +0300 Subject: [PATCH] Update Role.hpp --- module/Library/DPP/Role.hpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/module/Library/DPP/Role.hpp b/module/Library/DPP/Role.hpp index 25a507d1..52dea383 100644 --- a/module/Library/DPP/Role.hpp +++ b/module/Library/DPP/Role.hpp @@ -59,11 +59,7 @@ struct DpRole /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~DpRole() noexcept - { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); - } + ~DpRole() noexcept { Cleanup(); } /* -------------------------------------------------------------------------------------------- * Copy assignment operator (disabled). */ @@ -74,14 +70,24 @@ struct DpRole DpRole & operator = (DpRole && o) noexcept { if (this != &o) { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); + Cleanup(); // Transfer members values mPtr = std::move(o.mPtr); mOwned = o.mOwned; } return *this; } + /* -------------------------------------------------------------------------------------------- + * Release any referenced resources and default to an empty/invalid state. + */ + void Cleanup() + { + // Do we own this to try delete it? + if (!mOwned && mPtr) { + // Not our job, simply forget about it + [[maybe_unused]] auto p = mPtr.release(); + } else mPtr.reset(); // We own this so delete the instance + } /* -------------------------------------------------------------------------------------------- * Validate the managed handle. */