mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-05 03:37:28 +01:00
fixed possible memory leaks in the constructor and assignment operator of SharedPtr reported by issue #287
This commit is contained in:
parent
efc1585ae3
commit
6e92bdc01e
@ -119,9 +119,14 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr(C* ptr): _pCounter(new RC), _ptr(ptr)
|
SharedPtr(C* ptr)
|
||||||
|
try :
|
||||||
|
_pCounter(new RC), _ptr(ptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
catch (...) {
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
|
|
||||||
template <class Other, class OtherRP>
|
template <class Other, class OtherRP>
|
||||||
SharedPtr(const SharedPtr<Other, RC, OtherRP>& ptr): _pCounter(ptr._pCounter), _ptr(const_cast<Other*>(ptr.get()))
|
SharedPtr(const SharedPtr<Other, RC, OtherRP>& ptr): _pCounter(ptr._pCounter), _ptr(const_cast<Other*>(ptr.get()))
|
||||||
@ -143,10 +148,8 @@ public:
|
|||||||
{
|
{
|
||||||
if (get() != ptr)
|
if (get() != ptr)
|
||||||
{
|
{
|
||||||
RC* pTmp = new RC;
|
SharedPtr tmp(ptr);
|
||||||
release();
|
swap(tmp);
|
||||||
_pCounter = pTmp;
|
|
||||||
_ptr = ptr;
|
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user