diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h index bd7f28cae..9c64ac044 100644 --- a/include/utils/RefBase.h +++ b/include/utils/RefBase.h @@ -333,9 +333,10 @@ sp::~sp() template sp& sp::operator = (const sp& other) { - if (other.m_ptr) other.m_ptr->incStrong(this); + T* otherPtr(other.m_ptr); + if (otherPtr) otherPtr->incStrong(this); if (m_ptr) m_ptr->decStrong(this); - m_ptr = other.m_ptr; + m_ptr = otherPtr; return *this; } @@ -351,9 +352,10 @@ sp& sp::operator = (T* other) template template sp& sp::operator = (const sp& other) { - if (other.m_ptr) other.m_ptr->incStrong(this); + U* otherPtr(other.m_ptr); + if (otherPtr) otherPtr->incStrong(this); if (m_ptr) m_ptr->decStrong(this); - m_ptr = other.m_ptr; + m_ptr = otherPtr; return *this; } @@ -466,10 +468,12 @@ wp& wp::operator = (T* other) template wp& wp::operator = (const wp& other) { - if (other.m_ptr) other.m_refs->incWeak(this); + weakref_type* otherRefs(other.m_refs); + T* otherPtr(other.m_ptr); + if (otherPtr) otherRefs->incWeak(this); if (m_ptr) m_refs->decWeak(this); - m_ptr = other.m_ptr; - m_refs = other.m_refs; + m_ptr = otherPtr; + m_refs = otherRefs; return *this; } @@ -478,8 +482,9 @@ wp& wp::operator = (const sp& other) { weakref_type* newRefs = other != NULL ? other->createWeak(this) : 0; + T* otherPtr(other.m_ptr); if (m_ptr) m_refs->decWeak(this); - m_ptr = other.get(); + m_ptr = otherPtr; m_refs = newRefs; return *this; } @@ -498,10 +503,12 @@ wp& wp::operator = (U* other) template template wp& wp::operator = (const wp& other) { - if (other.m_ptr) other.m_refs->incWeak(this); + weakref_type* otherRefs(other.m_refs); + U* otherPtr(other.m_ptr); + if (otherPtr) otherRefs->incWeak(this); if (m_ptr) m_refs->decWeak(this); - m_ptr = other.m_ptr; - m_refs = other.m_refs; + m_ptr = otherPtr; + m_refs = otherRefs; return *this; } @@ -510,8 +517,9 @@ wp& wp::operator = (const sp& other) { weakref_type* newRefs = other != NULL ? other->createWeak(this) : 0; + U* otherPtr(other.m_ptr); if (m_ptr) m_refs->decWeak(this); - m_ptr = other.get(); + m_ptr = otherPtr; m_refs = newRefs; return *this; }