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

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> 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;
} }