From 83f2ab79e03d60e18ffc6faad6cd5c6854f1f4fe Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sat, 18 Sep 2021 21:35:42 +0300 Subject: [PATCH] Update Guild.hpp --- module/Library/DPP/Guild.hpp | 38 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/module/Library/DPP/Guild.hpp b/module/Library/DPP/Guild.hpp index ac19d113..2db34d95 100644 --- a/module/Library/DPP/Guild.hpp +++ b/module/Library/DPP/Guild.hpp @@ -59,11 +59,7 @@ struct DpGuildMember /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~DpGuildMember() noexcept - { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); - } + ~DpGuildMember() noexcept { Cleanup(); } /* -------------------------------------------------------------------------------------------- * Copy assignment operator (disabled). */ @@ -75,13 +71,24 @@ struct DpGuildMember { 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. */ @@ -201,11 +208,7 @@ struct DpGuild /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~DpGuild() noexcept - { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); - } + ~DpGuild() noexcept { Cleanup(); } /* -------------------------------------------------------------------------------------------- * Copy assignment operator (disabled). */ @@ -217,13 +220,24 @@ struct DpGuild { 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. */