diff --git a/mdbx.h++ b/mdbx.h++ index eef2e409..2a8dcd19 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -3453,7 +3453,15 @@ public: void close(bool dont_sync = false); env_managed(env_managed &&) = default; - using inherited::operator=; + env_managed &operator=(env_managed &&other) { + if (MDBX_UNLIKELY(handle_)) + MDBX_CXX20_UNLIKELY { + assert(handle_ != other.handle_); + close(); + } + inherited::operator=(std::move(other)); + return *this; + } env_managed(const env_managed &) = delete; env_managed &operator=(const env_managed &) = delete; virtual ~env_managed() noexcept; @@ -3744,7 +3752,15 @@ class LIBMDBX_API_TYPE txn_managed : public txn { public: MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default; txn_managed(txn_managed &&) = default; - using inherited::operator=; + txn_managed &operator=(txn_managed &&other) { + if (MDBX_UNLIKELY(handle_)) + MDBX_CXX20_UNLIKELY { + assert(handle_ != other.handle_); + abort(); + } + inherited::operator=(std::move(other)); + return *this; + } txn_managed(const txn_managed &) = delete; txn_managed &operator=(const txn_managed &) = delete; ~txn_managed() noexcept; @@ -3939,7 +3955,16 @@ public: void close(); cursor_managed(cursor_managed &&) = default; - using inherited::operator=; + cursor_managed &operator=(cursor_managed &&other) { + if (MDBX_UNLIKELY(handle_)) + MDBX_CXX20_UNLIKELY { + assert(handle_ != other.handle_); + close(); + } + inherited::operator=(std::move(other)); + return *this; + } + cursor_managed(const cursor_managed &) = delete; cursor_managed &operator=(const cursor_managed &) = delete; ~cursor_managed() noexcept { ::mdbx_cursor_close(handle_); }