mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Fix reference count bug in SharedPtr container
This commit is contained in:
@@ -189,9 +189,7 @@ public:
|
||||
*/
|
||||
~SharedPtr ()
|
||||
{
|
||||
if (m_p != nullptr)
|
||||
if (m_p->decReferenceCount (false))
|
||||
ContainerDeletePolicy <T>::destroy (m_p);
|
||||
release (m_p);
|
||||
}
|
||||
|
||||
/** Returns `true` if the container is not pointing to an object. */
|
||||
@@ -227,7 +225,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// Acquire a reference to u for the caller.
|
||||
// Acquire a reference to u for the caller if not null.
|
||||
//
|
||||
template <class U>
|
||||
static T* acquire (U* u) noexcept
|
||||
@@ -237,6 +235,14 @@ private:
|
||||
return u;
|
||||
}
|
||||
|
||||
// Release a reference to t if not null.
|
||||
//
|
||||
static void release (T* t) noexcept
|
||||
{
|
||||
if (t != nullptr)
|
||||
t->decReferenceCount ();
|
||||
}
|
||||
|
||||
// Swap ownership of the currently referenced object.
|
||||
// The caller receives a pointer to the original object,
|
||||
// and this container is left with the passed object. No
|
||||
@@ -257,8 +263,7 @@ private:
|
||||
SharedPtr& assign (U* u)
|
||||
{
|
||||
if (m_p != u)
|
||||
SharedPtr <T> old (
|
||||
this->swap (acquire (u)));
|
||||
release (this->swap (acquire (u)));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user