Fixed self-assignment in cv::Ptr::operator =
A self-assignment leads to a call of release() with refcount being 2. In the release() method, refcount is decremented and then successfully checked for being 1. As a consequence, the underlying data is released. To prevent this, we test for a self-assignment
This commit is contained in:
parent
3334b1437b
commit
efc1c39315
@ -2624,6 +2624,8 @@ template<typename _Tp> inline Ptr<_Tp>::Ptr(const Ptr<_Tp>& _ptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Tp> inline Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& _ptr)
|
template<typename _Tp> inline Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& _ptr)
|
||||||
|
{
|
||||||
|
if (this != &_ptr)
|
||||||
{
|
{
|
||||||
int* _refcount = _ptr.refcount;
|
int* _refcount = _ptr.refcount;
|
||||||
if( _refcount )
|
if( _refcount )
|
||||||
@ -2631,6 +2633,7 @@ template<typename _Tp> inline Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& _p
|
|||||||
release();
|
release();
|
||||||
obj = _ptr.obj;
|
obj = _ptr.obj;
|
||||||
refcount = _refcount;
|
refcount = _refcount;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user