diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index ec012f77..7ca09989 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -772,14 +772,21 @@ namespace winstd inline dplhandle& operator=(_In_ const dplhandle &h) { if (this != std::addressof(h)) { - handle_type h_new = duplicate_internal(h.m_h); - if (h_new) { + if (h.m_h) { + handle_type h_new = duplicate_internal(h.m_h); + if (h_new) { + if (m_h) + free_internal(); + + m_h = h_new; + } else + assert(0); // Could not duplicate the handle + } else { if (m_h) free_internal(); - m_h = h_new; - } else if (h.m_h) - assert(0); // Could not duplicate the handle + m_h = NULL; + } } return *this; }