diff --git a/module/Library/DPP/User.hpp b/module/Library/DPP/User.hpp index c4449e40..fd3c7df1 100644 --- a/module/Library/DPP/User.hpp +++ b/module/Library/DPP/User.hpp @@ -56,11 +56,7 @@ struct DpUser /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~DpUser() noexcept - { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); - } + ~DpUser() noexcept { Cleanup(); } /* -------------------------------------------------------------------------------------------- * Copy assignment operator (disabled). */ @@ -71,14 +67,24 @@ struct DpUser DpUser & operator = (DpUser && 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. */