Merge pull request #452 from Kontinuation/develop

Fixed possible memory leak in SharedPtr (issue #287)
This commit is contained in:
Günter Obiltschnig 2014-05-19 16:52:21 +02:00
commit c26eb63a5e

View File

@ -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>
SharedPtr(const SharedPtr<Other, RC, OtherRP>& ptr): _pCounter(ptr._pCounter), _ptr(const_cast<Other*>(ptr.get()))
@ -143,10 +148,8 @@ public:
{
if (get() != ptr)
{
RC* pTmp = new RC;
release();
_pCounter = pTmp;
_ptr = ptr;
SharedPtr tmp(ptr);
swap(tmp);
}
return *this;
}