mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 03:39:51 +00:00
Fix bug in SharedPtr<>::reset() where the pointer wasn't set to NULL when refcount > 1
This commit is contained in:
parent
103211509e
commit
af26dcaee4
@ -19,15 +19,11 @@ public:
|
||||
++m_count;
|
||||
}
|
||||
|
||||
bool release()
|
||||
void release()
|
||||
{
|
||||
--m_count;
|
||||
if (m_count == 0) {
|
||||
if (m_count == 0)
|
||||
delete this;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
long use_count() const
|
||||
@ -142,6 +138,9 @@ public:
|
||||
{
|
||||
if (m_ptr != ptr) {
|
||||
release();
|
||||
m_ptr = 0;
|
||||
m_refCount = 0;
|
||||
|
||||
if (ptr) {
|
||||
try {
|
||||
m_refCount = new SharedPtrRefCounterImpl<T, DefaultSharedPtrDeleter<T> >(ptr, DefaultSharedPtrDeleter<T>());
|
||||
@ -161,6 +160,9 @@ public:
|
||||
{
|
||||
if (m_ptr != ptr) {
|
||||
release();
|
||||
m_ptr = 0;
|
||||
m_refCount = 0;
|
||||
|
||||
if (ptr) {
|
||||
try {
|
||||
m_refCount = new SharedPtrRefCounterImpl<T, Deleter>(ptr, deleter);
|
||||
@ -218,10 +220,8 @@ private:
|
||||
// Removes the reference to the pointee.
|
||||
void release()
|
||||
{
|
||||
if (m_refCount && m_refCount->release()) {
|
||||
m_ptr = 0;
|
||||
m_refCount = 0;
|
||||
}
|
||||
if (m_refCount)
|
||||
m_refCount->release();
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,6 +129,16 @@ TEST(SharedPtr, Compare)
|
||||
EXPECT_EQ(5, *c);
|
||||
}
|
||||
|
||||
TEST(SharedPtr, ResetBugDoesntSetPtrToNull)
|
||||
{
|
||||
SharedPtr<int> a(new int(5));
|
||||
{
|
||||
SharedPtr<int> b(a);
|
||||
b.reset();
|
||||
}
|
||||
EXPECT_EQ(5, *a);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user