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